Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6
This is the forum to discuss the Wrox book Beginning PHP, Apache, MySQLWeb Development by Michael K. Glass, Yann Le Scouarnec, Elizabeth Naramore, Gary Mailer, Jeremy Stolz, Jason Gerner; ISBN: 9780764557446
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 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 Search this Thread Display Modes
  #1 (permalink)  
Old September 4th, 2004, 10:55 AM
Registered User
 
Join Date: Sep 2004
Location: Hooghalen, Drenthe, Netherlands.
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default chptr9 pg262 error with charlist.php

Hai,
When I fill in http://localhost/boek/h9/charlist.php i get the following error message in the browser

You have an error in your SQL syntax near 'ON c.id = pk.char_id AND p.id = pk.power_id' at line 2

I have no idea where this error is refering too and i typed all the data in the fields in again for 3 times now and still the same error message is in the browser. The config.php(page 249)& make_table.php are working fine. Someone a idea what it can be?

Reply With Quote
  #2 (permalink)  
Old December 31st, 2004, 01:26 PM
Registered User
 
Join Date: Dec 2004
Location: Glasgow, , United Kingdom.
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi

Did you ever get a solution to your problem? I'm getting the same syntax error in the charlist.php file although, in my case, make_table.php doesn't run; I created the database and tables using phpMyAdmin.



Reply With Quote
  #3 (permalink)  
Old December 31st, 2004, 03:35 PM
Authorized User
 
Join Date: Dec 2004
Location: , , .
Posts: 32
Thanks: 0
Thanked 0 Times in 0 Posts
Default

We need to see your code before any suggestions can be made. Typically, when you get an error like that, you've got something typed incorrectly in your code around that line that the error states. So...either keep looking or post the code so we can look at it.
Reply With Quote
  #4 (permalink)  
Old January 1st, 2005, 10:52 AM
Registered User
 
Join Date: Dec 2004
Location: Glasgow, , United Kingdom.
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I'm trying to run charlist.php on page 263 and get the following
error message displayed.

You have an error in your SQL syntax near 'ON c.id = pk.char_id AND p.id = pk.power_id' at line 2

The line from the code, reproduced below, is the same as the book and
the downloaded code.

$sql = "SELECT c.id, p.power FROM char_main c JOIN char_power p JOIN
   char_power_link pk ON c.id = pk.char_id AND p.id = pk.power_id";

I've even tried running the query from the mysql monitor and get the same result. I used phpMyAdmin to create the database and the tables since I couldn't get the make_table.php to run either!

I'm running under Linux Version 2.4.18-5, PHP Version 4.1.2,
MySQL version 3.23.49 and Apache version 1.3.23.

Thanks in advance for any help.


Reply With Quote
  #5 (permalink)  
Old January 1st, 2005, 03:27 PM
Authorized User
 
Join Date: Dec 2004
Location: , , .
Posts: 32
Thanks: 0
Thanked 0 Times in 0 Posts
Default

jaygee,

As far as I can tell, the way that you have the line of code currently typed looks correct. I copied/pasted it into my script and it works without any problems.

So...if you're willing, copy/paste all the code for charlist.php on this message board so that I can see if it works on my server.

The only other thing I can think of off the top of my head is that maybe the column headings in your table are incorrect or the tables don't exist. But that's probably not the case, because if I remember correctly, you'll get a specific error for that.

Anyway, post your code and we'll go from there. Cool?

Reply With Quote
  #6 (permalink)  
Old January 2nd, 2005, 03:52 PM
Registered User
 
Join Date: Dec 2004
Location: Glasgow, , United Kingdom.
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,

The code is as available from this web site but here it is:

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

$ord = $_GET['o'];
if (is_numeric($ord)){
 $ord = round(min(max($ord, 1), 3));
} else {
 $ord = 1;
}
$order = array(
   1 => 'alias ASC',
   2 => 'name ASC',
   3 => 'align ASC, alias ASC'
);

$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);

$sql = "SELECT c.id, p.power FROM char_main c JOIN char_power p JOIN
   char_power_link pk ON c.id = pk.char_id AND p.id = pk.power_id";

$result = mysql_query($sql) or die(mysql_error());
if (mysql_num_rows($result) > 0) {
 while ($row = mysql_fetch_assoc($result)) {
  $p[$row['id']][] = $row['power'];
 }
 foreach ($p as $key => $value) {
  $powers[$key] = implode(", ", $value);
 }
}

$sql = "SELECT c.id, n.alias FROM char_main c JOIN char_good_bad_link
   gb JOIN char_main n ON (c.id = gb.good_id AND n.id = gb.bad_id)
   OR (n.id = gb.good_id AND c.id = gb.bad_id)";

$result = mysql_query($sql) or die(mysql_error());
if (mysql_num_rows($result) > 0) {
 while ($row = mysql_fetch_assoc($result)) {
  $e[$row['id']][] = $row['alias'];
 }
 foreach ($e as $key => $value) {
  $enemies[$key] = implode(", ", $value);
 }
}
$table = "<table><tr><td align=\"center\">No characters currently
     exist.</td></tr></table>"
?>

 <html>
 <head>
 <title>Comic Book Appreciation</title>
 </head>
 <body>
 <img src='CBA_Tiny.gif' align='left' hspace='10'>
 <h1>Comic Book<br />Appreciation</h1><br />
 <h3>Character Database</h3>

<?php
$sql = "SELECT id, alias, real_name AS name, align
   FROM char_main ORDER BY ". $order[$ord];

$result = mysql_query($sql) or die(mysql_error());
if (mysql_num_rows($result) > 0) {
 $table = "<table border='0' cellpadding='5'>";
 $table .= "<tr bgcolor='#FFCCCC'><th>";
 $table .= "<a href='" . $_SERVER['PHP_SELF'] . "?o=1'>Alias</a>";
 $table .= "</th><th><a href='" . $_SERVER['PHP_SELF'] . "?o=2'>";
 $table .= "Name</a></th><th><a href='" . $_SERVER['PHP_SELF'];
 $table .= "?o=3'>Alignment</a></th><th>Powers</th>";
 $table .= "<th>Enemies</th></tr>";

 // build each table row
 while ($row = mysql_fetch_assoc($result)) {
  $bg = ($bg=='F2F2FF'?'E2E2F2':'F2F2FF');
  $pow = ($powers[$row['id']]==''?'none':$powers[$row['id']]);
  $ene = ($enemies[$row['id']]==''?'none':$enemies[$row['id']]);
  $table .= "<tr bgcolor='#" . $bg . "'><td><a href='charedit.php?c="
      . $row['id'] . "'>" . $row['alias']. "</a></td><td>"
      . $row['name'] . "</td><td align='center'>" . $row['align']
      . "</td><td>" . $pow . "</td><td align='center'>" . $ene
      . "</td></tr>";
 }

 $table .= "</table>";
 $table = str_replace('evil', 'evil', $table);
 $table = str_replace('good', 'good',
    $table);

}
echo $table;
?>
<br /><a href="charedit.php">New Character</a> &bull;
<a href="poweredit.php">Edit Powers</a>
</body>
</html>

Since the code has worked for you, I assume there must be something wrong with my setup; program versions or configuration files? See previous posting for details.
Are there any particular configuration settings which might cause this type of error?

Cheers,
Happy New Year!


Reply With Quote
  #7 (permalink)  
Old January 2nd, 2005, 06:09 PM
Authorized User
 
Join Date: Dec 2004
Location: , , .
Posts: 32
Thanks: 0
Thanked 0 Times in 0 Posts
Default

jaygee,

That code you supplied works perfectly fine on my system. But here's the thing...I know the code is available from this website. That's not what I'm asking for. I'm asking for YOUR code. The code you specifically typed into a text editor and is your script that you are running in your browser. If what you're telling me is that the code you just supplied is yours and that you simply copied/pasted the code from the downloadable code from this website and it's not working, then you have some other problem that I don't think I can help you with.

I'm not sure what else to say except that I'm testing it on the following sytem:

Windows XP Pro, Service Pack 1
Apache 2.0.52
PHP 4.3.9
MySQL 4.0.22-debug


So...your versions of the applications may very well be the root of your problem. The book was written around the following versions:

Apache 2.0.47
PHP 4.3.3
MySQL 4.0.15a

On an a side note, I have a Linux webserver as well that I'm currently using without PHP and MySQL, but I do ultimately plan on using it as my main server to run MySQL and PHP. I just simply haven't put forth the effort to run PHP, MySQL, or any of the scripts on it, because I'm still in the learning phase of PHP, and it's easiest at the moment to use my laptop which runs the above versions. That way I can learn and study PHP anywhere I want and not just at my house.

So...best of luck. Sorry I couldn't have been any more help. Let us know if you have any success.

Reply With Quote
  #8 (permalink)  
Old January 2nd, 2005, 10:36 PM
Registered User
 
Join Date: Dec 2004
Location: Glasgow, , United Kingdom.
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

bodenzord,

That's the thing. Yes I cut and paste the code into my Linux server while reading the book to learn. I'll try up grading my Apache, PHP and MySQL versions and see what happens.
Thanks for your help.


Reply With Quote
  #9 (permalink)  
Old January 2nd, 2005, 11:46 PM
Authorized User
 
Join Date: Dec 2004
Location: , , .
Posts: 32
Thanks: 0
Thanked 0 Times in 0 Posts
Default

best of luck and let us know how it goes. if that is truely the root of your problem, then it'll be a learning step and warning for us all. in your upgrade process, i'd be curious to know which application was the culprit. so...if you have the desire, upgrade one at a time and try out the script. that may very well point the finger. i guess i'd upgrade mysql first and then php with apache last.

oh! i just thought of something. try running the query from the command line and see if it works. if it does, then you shouldn't have to upgrade mysql. if it doesn't, then i'd bet that mysql is the problem and you might not have to upgrade the others.
Reply With Quote
  #10 (permalink)  
Old January 5th, 2005, 06:52 PM
Registered User
 
Join Date: Dec 2004
Location: Glasgow, , United Kingdom.
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

bodenzord,

Finally managed to get MySQL-client,-server and -shared-compat-4.1.8-0 installed and running with the e-smith server software. Good news is the query now works as required!
After the event I had another look at Chapter 1 and under the MySQL section I find "This book references version 4.0.15a.." Doh! As stated previously I was using 3.23.49. Ah well we live and learn.

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
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
Ch9 charlist.php undefined index grambell23 BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 2 July 7th, 2006 08:39 PM
SampleCode.php possible error vicsam Pro PHP 1 July 6th, 2005 04:22 PM
PHP code error Yee Dreamweaver (all versions) 1 October 21st, 2004 03:14 PM
Error: movie.php & commit.php on p182-186, ch6 willburke BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 0 October 12th, 2004 02:48 PM



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


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