dongyin8009 2010-08-04 18:03
浏览 29
已采纳

这个“for dummies”PHP代码有什么问题?

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>
”;
}
}
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.

  • 写回答

5条回答 默认 最新

  • drmq16019 2010-08-04 18:05
    关注

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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统