Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > PHP/MySQL > BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0
This is the forum to discuss the Wrox book Beginning PHP5, Apache, and MySQL Web Development by Elizabeth Naramore, Jason Gerner, Yann Le Scouarnec, Jeremy Stolz, Michael K. Glass; ISBN: 9780764579660
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old March 18th, 2005, 10:30 PM
Registered User
 
Join Date: Mar 2005
Location: Sault Ste. Marie, ON, Canada.
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default I cannot get this code to work , from the book/dl

<?php
require('config.php');

foreach ($_POST as $key => $value) {
  $$key = $value;
}

$conn = mysql_connect(SQL_HOST, SQL_USER, SQL_PASS)
  or die('Could not connect to MySQL database. ' . mysql_error());
mysql_select_db(SQL_DB, $conn);

switch ($action) {
  case "Create Character":
    $sql = "INSERT IGNORE INTO char_zipcode (id, city, state) " .
           "VALUES ('$zip', '$city', '$state')";
    $result = mysql_query($sql)
      or die(mysql_error());

    $sql = "INSERT INTO char_lair (id, zip_id, lair_addr) " .
           "VALUES (NULL, '$zip', '$address')";
    $result = mysql_query($sql)
      or die(mysql_error());
    if ($result) {
      $lairid = mysql_insert_id($conn);
    }

    $sql = "INSERT INTO char_main (id,lair_id,alias,real_name,align) " .
           "VALUES (NULL, '$lairid', '$alias', '$name', '$align')";
    $result = mysql_query($sql)
      or die(mysql_error());
    if ($result) {
      $charid = mysql_insert_id($conn);
    }

    if ($powers != "") {
      $val = "";
      foreach ($powers as $key => $id) {
        $val[] = "('$charid', '$id')";
      }
      $values = implode(',', $val);
      $sql = "INSERT IGNORE INTO char_power_link (char_id, power_id) " .
             "VALUES $values";
      $result = mysql_query($sql)
        or die(mysql_error());
    }

    if ($enemies != '') {
      $val = "";
      foreach ($enemies as $key => $id) {
        $val[] = "('$charid', '$id')";
      }
      $values = implode(',', $val);
      if ($align = 'good') {
        $cols = '(good_id, bad_id)';
      } else {
        $cols = '(bad_id, good_id)';
      }
      $sql = "INSERT IGNORE INTO char_good_bad_link $cols " .
             "VALUES $values";
      $result = mysql_query($sql)
        or die(mysql_error());
    }

    $redirect = 'charlist.php';
    break;

  case "Delete Character":
    $sql = "DELETE FROM char_main, char_lair " .
           "USING char_main m, char_lair l " .
           "WHERE m.lair_id = l.id AND m.id = $cid";
    $result = mysql_query($sql)
      or die(mysql_error());

    $sql = "DELETE FROM char_power_link WHERE char_id = $cid";
    $result = mysql_query($sql)
      or die(mysql_error());

    $sql = "DELETE FROM char_good_bad_link " .
           "WHERE good_id = $cid OR bad_id = $cid";
    $result = mysql_query($sql)
      or die(mysql_error());

    $redirect = 'charlist.php';
    break;

  case "Update Character":
    $sql = "INSERT IGNORE INTO char_zipcode (id, city, state) " .
           "VALUES ('$zip', '$city', '$state')";
    $result = mysql_query($sql)
      or die(mysql_error());

    $sql = "UPDATE char_lair l, char_main m " .
           "SET l.zip_id='$zip', l.lair_addr='$address', " .
           "alias='$alias', real_name='$name', align='$align' " .
           "WHERE m.id = $cid AND m.lair_id = l.id";
    $result = mysql_query($sql)
      or die(mysql_error());

    $sql = "DELETE FROM char_power_link WHERE char_id = $cid";
    $result = mysql_query($sql)
      or die(mysql_error());

    if ($powers != "") {
      $val = "";
      foreach ($powers as $key => $id) {
        $val[] = "('$cid', '$id')";
      }
      $values = implode(',', $val);
      $sql = "INSERT IGNORE INTO char_power_link (char_id, power_id) " .
             "VALUES $values";
      $result = mysql_query($sql)
        or die(mysql_error());
    }

    $sql = "DELETE FROM char_good_bad_link " .
           "WHERE good_id = $cid OR bad_id = $cid";
    $result = mysql_query($sql)
      or die(mysql_error());

    if ($enemies != '') {
      $val = "";
      foreach ($enemies as $key => $id) {
        $val[] = "('$cid', '$id')";
      }
      $values = implode(',', $val);
      if ($align == 'good') {
        $cols = '(good_id, bad_id)';
      } else {
        $cols = '(bad_id, good_id)';
      }
      $sql = "INSERT IGNORE INTO char_good_bad_link $cols " .
             "VALUES $values";
      $result = mysql_query($sql)
        or die(mysql_error());
    }

    $redirect = 'charlist.php';
    break;

  case "Delete Powers":
    if ($powers != "") {
      $powerlist = implode(',', $powers);

      $sql = "DELETE FROM char_power WHERE id IN ($powerlist)";
      $result = mysql_query($sql)
        or die(mysql_error());

      $sql = "DELETE FROM char_power_link " .
             "WHERE power_id IN ($powerlist)";
      $result = mysql_query($sql)
        or die(mysql_error());
    }

    $redirect = 'poweredit.php';
    break;

  case "Add Power":
    if ($newpower != '') {
      $sql = "INSERT IGNORE INTO char_power (id, power) " .
             "VALUES (NULL, '$newpower')";
      $result = mysql_query($sql)
        or die(mysql_error());
    }

    $redirect = 'poweredit.php';
    break;

  default:

    $redirect = 'charlist.php';
}
header("Location: $redirect");
?>
===========================

I keep getting the old there is an error with your mysql syntax error around " l, char_main m " .
           "SET l.zip_id='$zip'"
I'm new, please help

Reply With Quote
  #2 (permalink)  
Old April 20th, 2005, 12:33 AM
Registered User
 
Join Date: Apr 2005
Location: Anthony, New Mexico, USA.
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

One thing you'll want to make sure of, that you have MySQL 4.0.4 or later. The manual I'm looking at online says that's when multi-table UPDATE was implemented.

I'm not entirely sure, but you might have a problem with the multi-table UPDATE not knowing which table 'alias', 'real_name' or 'align' are supposed to be in. (ie, 1.alias, or m.alias) Everything else in the line (repeated below) is defined.

$sql = "UPDATE char_lair l, char_main m " .
           "SET l.zip_id='$zip', l.lair_addr='$address', " .
           "alias='$alias', real_name='$name', align='$align' " .
           "WHERE m.id = $cid AND m.lair_id = l.id";

I don't see anything else that looks wrong about it, and I haven't had a chance to try the programs yet... I've only had the book for a day.

                                             ..KARL...

<SPAN ATTRIB="DORK">KarlGG</SPAN>
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
mail through cdosys.dl Amit singla ASP.NET 1.0 and 1.1 Professional 3 October 26th, 2006 06:41 AM
code clinic - Why wont example asp code work? jardbf Classic ASP Basics 3 April 27th, 2006 06:22 PM
How do i dl files that i have uploaded Beginner123 VB How-To 0 March 2nd, 2005 09:42 PM
Code from Book did not work! mnongkhlaw Wrox Book Feedback 2 October 27th, 2003 11:34 PM
Code from Book did not work! mnongkhlaw Classic ASP Databases 0 October 27th, 2003 06:30 AM



All times are GMT -4. The time now is 03:38 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.