Correct PHP Syntax

Giarc86

Expert Member
Joined
May 28, 2008
Messages
1,243
Reaction score
4
Hoping someone can help me. What would the correct syntax be to insert a Form/Input button into a PHP table? I want to insert a checkbox for each row.

I get a "Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ',' or ';' " which I did Google but I can't find where I am missing anything or where any \ should go.

PHP:
<?php
echo "<table width='800' border='1' align='center' cellpadding='3' cellspacing='1'>

<tr>
<th>First Level.</th>
<th>Second Level</th>
<th>Third Level</th>
<th>Date</th>

</tr>";

while($row = mysql_fetch_array($result))
  {
	  
  echo "<tr>";
  echo "<td>" 
     '<form name="udform" method="GET" action="./test_udel.php"  enctype="multipart/form-data">' "</td>" ;
  echo "<td>" 
      ' <input type="checkbox" name="delete[]" value="' . $row['id'] . '" />' "</td>";
  echo "<td>" 
      ' </form> ' "</td>" ;
  echo "<td>" . $row['firstlevel'] . "</td>";
  echo "<td>" . $row['secondlevel'] . "</td>";
  echo "<td>" . $row['thirdlevel'] . "</td>";
  echo "<td>" . $row['mydate'] . "</td>";
  echo "</tr>";
  
    }
echo "</table>";
?>

Any help would be appreciated
Thanks
 
Could it be that you need to escape out some of the apostrophes/qoutes(what are those called again - inverted comma's? lol I'm drawing a blank) in those echo statements? Like inside the while loop, the second line:

echo "<td>"

Doesn't that second " essentially close the echo statement.. which is why the error says it's expecting a ';'

I'm a designer not a coder, so I could be wrong wrt to php.
 
Last edited:
PHP:
  echo "<tr>";
  echo "<td><form name=\"udform\" method=\"GET\" action=\"./test_udel.php\" enctype=\"multipart/form-data\"></td>";
  echo "<td><input type=\"checkbox\" name=\"delete[]\" value=".$row['id']."></td>";
  echo "<td></form></td>" ;
  echo "<td>" . $row['firstlevel'] . "</td>";
  echo "<td>" . $row['secondlevel'] . "</td>";
  echo "<td>" . $row['thirdlevel'] . "</td>";
  echo "<td>" . $row['mydate'] . "</td>";
  echo "</tr>";
 
Last edited:
PHP:
<?php
...
while($row = mysql_fetch_array($result))
  {
	  
  echo "<tr>";
  echo "<td>" 
     '<form name="udform" method="GET" action="./test_udel.php"  enctype="multipart/form-data">' "</td>" ;
 ...

?>

Any help would be appreciated
Thanks

See that? echo "<td>" '<form name

Between your " and your ' at least a . will concatenate them. even better
echo '<td><form..etc'
 
NO!


HTML:
<form method="POST" action="handler.php" >
<table>
<thead>
<tr>
<th>My Header</th>
<th>Delete</th>
</tr>
</thead>
<tbody>
<?php
for (mysql_fetch_array($result) = $row)
{
?>

<tr>
<td><?php echo $row['mykey']; ?></td>
<td><input type="checkbox" name="delete_<?php echo $row['id']; ?>" value="<?php echo $row['id']; ?>" /></td>
</tr>

<?php
}
?>
</tbody>
</table>
</form>
 
Last edited:
agreed. don't parse html through php if you don't have to.
end tags are also optional in html table sub-elements, as with list items.
 
You should be using mysql_fetch_assoc() and not mysql_fetch_array()
 
Also you can do this in PHP when mixing HTML a lot

Code:
<?php if ($myvale==True): ?>
<?php else: ?>
<?php endif ?>
and

Code:
<?php for($icount = 1; $icount < 10; $icount++): ?>
<?php endfor ?>

Its easier than having to maintain {}
 
NO!


HTML:
<form method="POST" action="handler.php" >
<table>
<thead>
<tr>
<th>My Header</th>
<th>Delete</th>
</tr>
</thead>
<tbody>
<?php
for (mysql_fetch_assoc($result) = $row)
{
?>

<tr>
<td><?=$row['mykey'];?></td>
<td><input type="checkbox" name="delete_<?=$row['id']; ?>" value="<?$row['id']; ?>" /></td>
</tr>

<?php
}
?>
</tbody>
</table>
</form>

If short tags are enabled, this would be better
 
Thanks for all the help guys :) Appreciate it. dabouncer's solution worked, but since then I had to scrap the table and redo it, and it is still working fine now.
Thanks :)
 
Top
Sign up to the MyBroadband newsletter
X