1

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.

1
  • If you mean you are getting Parse error: Syntax error: Unexpected < in... then the code that is causing the problem is not shown above. However you do have several syntax errors because you did not escape the literal double quotes in your double quoted string. Commented Jun 8, 2012 at 22:30

5 Answers 5

7

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.

Sign up to request clarification or add additional context in comments.

Comments

4

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

Comments

1

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

Comments

0

You should scape your double quotes or just use sigle quotes for the echo statement.

Comments

0

You cannot use double quotes (") for specify strings in a double quote statement echo "<div id="pong" >; without the backslash \". You have three choices:

  1. Change your first and last " for '
  2. Put backslashes in your code.
  3. Concatenate string like: echo "<form method="."post".">"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.