NassMoh
NassMoh

Reputation: 37

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:

 <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.

Upvotes: 0

Views: 49400

Answers (3)

Nick Rolando
Nick Rolando

Reputation: 26177

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

Upvotes: 7

Pheonix
Pheonix

Reputation: 6052

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

Upvotes: 2

Niet the Dark Absol
Niet the Dark Absol

Reputation: 324750

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.

Upvotes: 0

Related Questions