无法在我的第一个php中发现语法错误

我正在尝试将php添加到表单中,以便从数据库中填充它,以进行作业分配。我收到一个解析错误“解析错误:语法错误,/l7p1.php中第97行的文件意外结束”。盯着这个文件几个小时后,我似乎找不到我的错误。


在将它们全部更改为单引号之后,我本来在任何时候都得到了“意外(T_VARIABLE)”(希望有一些我不理解的地方,因为我不确定这是如何改变的)将错误移动到代码的最后一行和“文件意外结尾”。


这是php的第一部分,旨在用数据库中的项目(工具)填充表单



<?php

                                $db=mysli_connect(null,null,null,'weblab')

                                  or die("Can't connect to db:".mysqli_connect_error($db));

                                $q = "select tool_item_no, tool_name, tool_price, tool_weight";

                                $q .= "from tool_t";

                                $q .= "order by tool_name";

                                $dbResult = mysqli_query($db,$q)

                                  or die("Database query error" . mysqli_error($db));

                                $num = mysqli_num_rows($dbResult);

                                if ($num == 0){

                                        echo"<h3>No Data</h3>";

                                        }

                                while ($row = mysqli_fetch_assoc($dbResult)) {

                                        $tool_item_no = $row["tool_item_no"];

                                        $tmool_name = $row['tool_name'];

                                        $tool_price = $row['tool_price'];

                                        $tool_weight = $row['tool_weight'];

                                        echo "<label for = '$tool_name'>Name : $toolname<br/>Price : $tool_price<br/>Weight : $tool_weight<br/>How many

                                        $tool_name for this order?

                                        <input type = 'text' name = '$tool_name' id = '$tool_item_no' size = ]'5'/></label><br/><br/>

                                }

?>



BIG阳
浏览 197回答 3
3回答

月关宝盒

以下应该工作。您混用了单引号,而您还不能设置Ca n't,所以需要将其括在“”中以转义单引号。我还在您的php中添加了“”并添加了句点。您需要查找有关php变量和字符串的更多教程。&nbsp; &nbsp; $db=mysli_connect(null,null,null,'weblab')&nbsp; &nbsp; &nbsp; or die("Can't connect to db:".mysqli_connect_error($db));&nbsp; &nbsp; $q = "select tool_item_no, tool_name, tool_price, tool_weight";&nbsp; &nbsp; $q .= "from tool_t";&nbsp; &nbsp; $q .= "order by tool_name";&nbsp; &nbsp; $dbResult = mysqli_query($db,$q)&nbsp; &nbsp; &nbsp; or die("Database query error" . mysqli_error($db));&nbsp; &nbsp; $num = mysqli_num_rows($dbResult);&nbsp; &nbsp; if ($num == 0){&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; echo"<h3>No Data</h3>";&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; while ($row = mysqli_fetch_assoc($dbResult)) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $tool_item_no = $row["tool_item_no"];&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $tmool_name = $row['tool_name'];&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $tool_price = $row['tool_price'];&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $tool_weight = $row['tool_weight'];&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; echo "<label for = ".$tool_name.">Name : ".$toolname".<br/>Price : ".$tool_price."<br/>Weight : ".$tool_weight."<br/>How many&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ".$tool_name." for this order?&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <input type = 'text name = ".$tool_name." id = ".$tool_item_no." size = ]'5'/></label><br/><br/>"&nbsp; &nbsp; }&nbsp; &nbsp; $db=mysli_connect(null,null,null,'weblab')&nbsp; &nbsp; &nbsp; or die("Can't connect to&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; db:".mysqli_connect_error($db));&nbsp; &nbsp; $q = 'select state_abbr, state_name ';&nbsp; &nbsp; $q .= 'from state_t ';&nbsp; &nbsp; $q .= 'order by state_name;';&nbsp; &nbsp; $dbResult = mysqli_query($db,$q)&nbsp; &nbsp; &nbsp; or die('Database query error' .&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;mysqli_error($db));&nbsp; &nbsp; $num = mysqli_num_rows($dbResult);&nbsp; &nbsp; if ($num == 0){&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; echo '<option value=&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;'$state_abbr' >$state_name</option>';&nbsp; &nbsp; echo '<option>Error</option>';&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; while ($row = mysqli_fetch_assoc($dbResult)) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $state_abbr = $row[state_abbr];&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $state_name = $row[state_name];&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; echo '<option value= '.$state_abbr.'>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;'.$state_name.'</option>';&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }

温温酱

PHP中的单引号和双引号之间的区别在于,双引号中的字符串可以被解释,但单引号中的字符串不能被解释(请参见此处)。在PHP中,当出现意外的EOF错误时,这是很多时间,因为您忘记了右括号,括号,引号,...在您发布的第一部分代码中,语法高亮显示了您在最后一行忘记在echo语句中关闭双引号的情况。您使用单引号引起的问题之一可能是由于字符串中的单引号引起的。如果用单引号引起来的字符串中有一个单引号,则PHP解释程序会认为您正在关闭字符串。

波斯汪

在您的第一段代码中。您的回声需要右引号和分号。
打开App,查看更多内容
随时随地看视频慕课网APP