Page 1 of 1

What's wrong with this code?

Posted: Thu Aug 21, 2003 3:12 pm
by King James
Here's the situation:

I'm new at all of this programming stuff, but I have to learn it for my company. I bought PHP & MYSQL for Dummies (yes, I know it's lame) and I'm doing one of the excersises in the book, and I typed in the code EXACTLY as it says. The problem is, I get an error everytime I try to load the thing. So, I'm hoping someone here can help me. Here's the code:

<!-- Program Name: mysql_send.php
Description: PHP Program that sends an SQL query to the
MySQL server and displays the results.
-->
<html>
<head>
<title> SQL Query Sender</title>
</head>
<body>
<?php
$host="127.0.0.1";
$user="root";
$password="";

/* Section that executes query */
if (@$form == "yes")
{
mysql_connect($host,$user,$password);
mysql_select_db($database);
$query = stripSlashes($query) ;
$result = mysql_query($query);
echo "Database Selected: <b>$database</b><br>
Query: <b>$query</b>
<h3>Results</h3>
<hr>";
if ($result == 0)
echo("<b>Error ".mysql_errno().": ".mysql_error()."</b>");
elseif (@mysql_num_rows($result) == 0)
echo("<b>Query Completed. No Results Returned.</b><br>");
else
{
echo "<table border="1">
<thead>
<tr>";
for ($i = 0; $i < mysql_num_fields($result); $i++)
{
echo("<th>" . mysql_field_name($result,$i) . "</th>");
}
echo "</tr>
</thead>
<tbody>";
for ($i = 0; $i < mysql_num_rows($result); $i++)
{
echo "<tr>";
$row = mysql_fetch_row($result)
for ($j = 0; $j < mysql_num_fields($result); $j++)
{
echo("<td>" . $row[$j] . "</td>");
}
echo "</tr>";
}
echo "</tbody>
</table>";
}

echo "<hr><br>
<form action=$PHP_SELF method=post>
<input type=hidden name=query value=\"$query\">
<input type=hidden name=database value=$database>
<input type=submit name=\"querybutton\" value=\"New Query\">
<input type=submit name=\"querybutton\" value=\"Edit Query\">
</form>";
unset($form);
exit();
}

/* Section that requests user input of query */
@$query= stripSlashes($query);
if (@queryButton != "Edit Query")
{
$database = " ";
$query = " ";
}
?>

<form action=<?php echo $PHP_SELF ?>?form=yes method="post">

<table>
<tr>
<td align="right"><b>Type in database name</b></td>
<td>
<input type=text name="database" value=<?php echo $database ?> >
</td>
</tr>
<tr>
<td align="right" valign="top"><b>Type in SQL query</b></td>
<td><textarea name="query" cols="60" rows="10"><?php echo $query ?>
</textarea>
</td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" value="submit Query"></td>
</tr>
</table>
</form>
</body>
</html>

And here's the error:

Parse error: parse error, unexpected T_LNUMBER, expecting ',' or ';' in C:\Program Files\Apache Group\Apache2\htdocs\mysql_send.php on line 32

Can someone PLEEEEEEEEEEAAAAAAAAAAASEEEEEEEEEE help me??? I'm in bad shape :)

Posted: Thu Aug 21, 2003 3:40 pm
by lstring
James,

Replace this line
echo "<table border="1">

with
echo "<table border=\"1\">

You need to use a backslash to escape quotes within quotes in echo or print statements. Your original echo statement ends at this point
echo "<table border=1" See?

Hope this helps!

Posted: Fri Aug 22, 2003 9:08 am
by King James
Sure enough, it works....thank you so much. Now I have another problem though, please view my other thread.

Thanks again.