Reputation: 673
I am using a simple loop that looks like this:
$query = "SELECT * FROM $username";
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_array($result)){
echo $row['id']. " - ". $row['file'];
echo "<br />";
echo "<form method="post" action="" style="width: 80px">
<input name="Checkbox1" type="checkbox" /><input name="Submit1" type="submit" value="submit" /></form>";
When i run it like this I get an error that the < is unexpected. I believe I may be doing something entirely wrong. Is there some other approach that would output a table within a php loop.
Upvotes: 1
Views: 2205
Reputation: 2150
You cannot use double quotes ("
) for specify strings in a double quote statement echo "<div id="pong" >;
without the backslash \"
. You have three choices:
"
for '
"<form method="."post".">"
Upvotes: 0
Reputation: 3780
You should scape your double quotes or just use sigle quotes for the echo statement.
Upvotes: 0
Reputation: 1901
You have quotes within quotes. They should be escaped using \
.
echo "<form method=\"post\" action=\"\" style=\"width: 80px\">...";
You can also use single quotes:
echo '<form method="post" action="" style="width: 80px">...';
The difference between single and double quotes is that single quotes does not show variables:
<?php
$a = 'b';
echo '$a'; // output: $a
echo "$a"; // output: b
echo $a; // output b
Upvotes: 4
Reputation: 68790
I don't know if it's the only problem, but you must escape your double quotes :
echo "<form method=\"post\" action=\"\" style=\"width: 80px\">
<input name=\"Checkbox1\" type=\"checkbox\" />
<input name=\"Submit1\" type=\"submit\" value=\"submit\" />
</form>";
You can also use simple quote to delimite your string :
echo '<form method="post" action="" style="width: 80px">
<input name="Checkbox1" type="checkbox" />
<input name="Submit1" type="submit" value="submit" />
</form>';
Upvotes: 1
Reputation: 943564
See this line:
echo "<form method="post" action="" style="width: 80px">
^ ^
| End of string
Start of string
Escape quotes (\"
) inside strings delimited with the same type of quotes.
Upvotes: 7