I am running PHP5 on a free web server and I am trying to learn PHP reading a “for dummies” book…It gives me some code to run and for some infuriating reason I get errors on every line that echos HTML.
here is the code. specifics have been Xed out but they are accurate:
<?php
/* Program: mysql_up.php
* Desc: Connects to MySQL Server and
* outputs settings.
*/
echo “<html>
<head><title>Test MySQL</title></head>
<body>”;
$host=”XXXX”;
$user=”XXXX”;
$password=”XXXX”;
$cxn = mysqli_connect($host,$user,$password);
$sql=”SHOW STATUS”;
$result = mysqli_query($cxn,$sql);
if($result == false)
{
echo “<h4>Error: “.mysqli_error($cxn).”</h4>”;
}
else
{
/* Table that displays the results */
echo “<table border=’1’>
<tr><th>Variable_name</th>
<th>Value</th></tr>”;
for($i = 0; $i < mysqli_num_rows($result); $i++)
{
echo “<tr>”;
$row_array = mysqli_fetch_row($result);
for($j = 0;$j < mysqli_num_fields($result);$j++)
{
echo “<td>”.$row_array[$j].”</td>\n”;
}
}
echo “</table>”;
}
?>
</body></html>
Whenever it gets to a line that echos HTML I get this error or similar:
Parse error: syntax error, unexpected ‘>’ in /home/a7613610/public_html/mysql_up.php on line 6
I want to learn PHP but when it reports errors in supposedly good code it makes me not want to.
The code is riddled with fancy quotes (
“and”) which PHP cannot cope with. You could use your text editor to do a find and replace for both characters with the generic double quote character".Although it definitely looks like you’re not using a plain text editor (see Mike Caron’s answer), I hope you’re using one. Word-processing and rich text editing software is not designed for writing programs and scripts.OK, so you’re using Notepad to write your PHP code. That’s great, but be aware that some eBook readers and even some books themselves mess with quote characters in code blocks and turn them fancy. This is one reason why copying and pasting code is frowned on 😉
Also, if you want to learn PHP, or any form of programming in general, you should probably not expect books and tutorials to be perfect 😉