PHP 错误:“语法错误,意外的 T_STRING,需要 ',' 或 ';'”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7940593/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 03:39:57  来源:igfitidea点击:

PHP error: "syntax error, unexpected T_STRING, expecting ',' or ';'"

phpsyntax-error

提问by NassMoh

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.

我在您的网站和其他网站上查找了此问题,但找不到解决方案。

回答by Nick Rolando

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 sizevalues too towards the bottom

此外,你可以不做,但你也应该size在底部引用你的价值观

回答by Pheonix

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

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

Escape the Double quotes

转义双引号

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

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

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

OR

或者

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

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

回答by Niet the Dark Absol

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>