I took the advice of people on this board and have been experimenting with writing my own code to call data from a mySQL table. The directions I'm using are at http://kresch.com/articles/art059_4.htm
I got the top example to work fine but then I tried the bottom example and I get the following error:
Parse error: parse error, unexpected T_CLASS, expecting ']' in /home/pstvalu/public_html/test.php on line 19
Here's my php code (which should be just like the example but with my data filled in its place). If I'm corre3ct, line 19 is the one beginning with "printf". So what went wrong? Why and where is is expecting a "]" that isn't in the example I'm learning from? Thanks.
<?php
<html>
<body>
this is just text
</P>
$db = mysql_connect("localhost\", \"pstvalu_director\", \"XXXXXXXXX\");
mysql_select_db(\"pstvalu_directory\",$db);
$result = mysql_query(\"SELECT * FROM alumni\",$db);
if ($myrow = mysql_fetch_array($result))
echo \"<table border=1>\n\";
echo \"<tr><td>Last Name</td><td>First Name</td><td>Class</td><td>Position</td><td>Employer</td><td>City</td><td>State</td><td>E-mail</td><td>Phone</td><td>Last Updated</td></tr>\n\";
do {
printf(\"<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>\n\", $myrow[lastname], $myrow[firstname], $myrow[class], $myrow[position], $myrow[employer], $myrow[city], $myrow[state], $myrow[email], $myrow[phone], $myrow[updated]);
}
while ($myrow = mysql_fetch_array($result));
echo \"</table>\n\";
}
else {
echo \"Sorry, no records were found!\";
}
</body>
</html>
?>
Nip it in the bud!







Peter J. Boettcher posted this at 20:18—7th October 2002.
They have: 812 posts
Joined: Feb 2000
I'm not a PHP expert but maybe "class" is a reserved word to the language that you can't use as a variable or column name.
PJ | Are we there yet?
pjboettcher.com
fifeclub posted this at 20:54—7th October 2002.
He has: 675 posts
Joined: Feb 2001
I think "class" is okay for a column name but I'm not positive. It's wierd that it showed as green in my code above, but it isn't listed on the mySQL website as being reserved. I also think it's okay because I accessed the same data with no problems using the first example (on the page I was learning from).
But I gave your suggestion a try and reverted all of those named columns to numbers starting at zero, and it instead gave me the parse error message "unexpected '}'" on line 23. (That's the line above "else {" )
As usual, the more I try the more I get more confused.
Nip it in the bud!
fifeclub posted this at 22:29—7th October 2002.
He has: 675 posts
Joined: Feb 2001
Found it! It was a typo with a missing { from way earlier in the script. Thanks. I'll probably be back again as I try to figure this all out.
Nip it in the bud!