简体   繁体   English

PHP错误:“语法错误,意外的T_STRING,期望为','或';'”

[英]PHP error: “syntax error, unexpected T_STRING, expecting ',' or ';'”

I got this message (syntax error, unexpected T_STRING, expecting ',' or ';') when I was trying to run the following code: 当我尝试运行以下代码时,收到此消息(语法错误,意外的T_STRING,期望为“;”或“;”):

 <html>
 <head>

 </head>
 <body>
 <title>Num One Website</title>

 <?
 $con = mysql_connect("","","");
 if (!$con)
   {
   die('Could not connect: ' . mysql_error());
   }

 mysql_select_db("", $con);

 $result1 = mysql_query("SELECT * FROM Students") ;

 echo "<form action='ConfirmEnter.php' method='post'>";
 echo "<input type="Radio" name="mark" value="mt">"."MidTerm<br>";
 echo "<input type="Radio" name="mark" value="pr">"."Project<br>";
 echo "<input type="Radio" name="mark" value="fi">"."Final<br>";
 echo "<table border cellpadding=3>"; 
 echo "<tr>"; 
 echo "<th>ID</th>";
 echo "<th>MidTerm</th>"; 
 echo "<th>Project</th>"; 
 echo "<th>Final</th>";
 echo "<th>Total</th>". "</tr>";

 $count=1;

 while($row1 = mysql_fetch_array($result1)) 
  { 
  echo "<tr>";
  echo "<td><input name='ID[]' readonly='readonly' value='". $row1['ID'] ."'      size=5/></td> "; 
  echo "<td><input type='text' name='mt[]' size=5 value='0.0' /></td>";
  echo "<td><input type='text' name='pr[]' size=5 value='0.0' /></td>";
  echo "<td><input type='text' name='fi[]' size=5 value='0.0' /></td>";
  echo "</tr>";
 $count++;
  } 
 echo "</table>"; 
 echo "<input type='submit' value='Submit' />";
 echo "</form>"; 
 mysql_close($con);


 ?>

 </body>
 </html>

The error in these lines: 这些行中的错误:

 echo "<input type="Radio" name="mark" value="mt">"."MidTerm<br>";
 echo "<input type="Radio" name="mark" value="pr">"."Project<br>";
 echo "<input type="Radio" name="mark" value="fi">"."Final<br>";

I looked for this problem in your website and other websites but I couldn't find the solution for it. 我在您的网站和其他网站中寻找了此问题,但找不到解决方案。

Here your syntax is off. 在这里,您的语法已关闭。 use single quotes like you did in your form tag, or escape the double quotes 像在表单标签中一样使用单引号,或者转义双引号

echo "<input type=\"Radio\" name=\"mark\" value=\"mt\">"."MidTerm<br>";
...
...

and you need to fix this line too, here: 您也需要在以下位置修复此行:

echo "<table border=\"3\" cellpadding=\"3\">";

also, you can get by without, but you should quote your size values too towards the bottom 同样,您也可以没有,但是您也应该在底部引用size

echo "<input type="Radio" name="mark" value="mt">"."MidTerm<br>";

Escape the Double quotes 转义双引号

echo "<input type=\\"Radio\\" name=\\"mark\\" value=\\"mt\\">"."MidTerm<br>";

similarly for other lines. 其他行也一样。

====== ======

alternatively use single quotes in one of the places. 或者在其中一个地方使用单引号。

echo '<input type="Radio" name="mark" value="mt">'.'MidTerm<br>';

OR 要么

echo "<input type='Radio' name='mark' value='mt'>"."MidTerm<br>";

Why do you think you have an error? 为什么您认为自己有错误? You're not escaping quotes in the string, of course it's not going to work. 您不是在转义字符串中的引号,当然这是行不通的。 Just add a \\ before the " in the <input> tag and you're all good. 只需在<input>标记中的"之前添加一个\\ ,就可以了。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 解析错误:语法错误,意外的“ href”(T_STRING),期望为“,”或“;” - Parse error: syntax error, unexpected 'href' (T_STRING), expecting ',' or ';' 语法错误,意外的T_GOTO,期待T_STRING - syntax error, unexpected T_GOTO, expecting T_STRING PHP语法错误,意外T_STRING - PHP syntax error, unexpected T_STRING PHP后期静态绑定—分析错误:语法错误,意外的T_STRING,预期的T_VARIABLE - PHP Late Static Binding — Parse error: syntax error, unexpected T_STRING, expecting T_VARIABLE PHP解析错误:语法错误,意外的T_STRING,预期的T_FUNCTION - PHP Parse error: syntax error, unexpected T_STRING, expecting T_FUNCTION 解析错误:语法错误,意外T_VARIABLE,期望PHP 5.3中的T_STRING - Parse error: syntax error, unexpected T_VARIABLE, expecting T_STRING in PHP 5.3 php解析错误:语法错误,意外的T_STRING,在构造上需要T_FUNCTION - php Parse error: syntax error, unexpected T_STRING, expecting T_FUNCTION on construct 语法错误,意外的 'st1ko' (T_STRING),期待 ')' - syntax error, unexpected 'st1ko' (T_STRING), expecting ')' PHP-解析错误:语法错误,意外的“ readphp”(T_STRING),期望为“,”或“;” - PHP- Parse error: syntax error, unexpected 'readphp' (T_STRING), expecting ',' or ';' 解析错误:语法错误,意外的&#39;(&#39;,在第26行的-------------- / admin.php中期望T_STRING - Parse error: syntax error, unexpected '(', expecting T_STRING in --------------/admin.php on line 26
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM