0

I run this code, and got this error:

 Parse error: syntax error, unexpected T_LNUMBER in C:\xampp\htdocs\Generate.php on line 5

What is the problem?

<?php
$satr=$_POST["satr"];
$soton=$_POST["soton"];
$bg=$_POST["bg"];
echo ("<table border="1" style="background-color:$bg">");
for($i=1;&i<=$satr;$i++)
{
    echo("<tr>");
    for($j=1;j<=$soton;$j++)
    {
        echo("<td>$soton</td>");
}
echo("</tr>");
}
echo("</table>");    

?>
Stephen Ostermiller
  • 23,933
  • 14
  • 88
  • 109

4 Answers4

2
    echo ("<table border='1' style='background-color:$bg'>");

    echo ('<table border="1" style="background-color:$bg">');

    echo "<table border=\"1\" style=\"background-color:$bg\">";

    echo '<table border="1" style="background-color:$bg">';

    echo "<table border='1' style='background-color:$bg'>";
1

You dont need the parenthesis and you need to escape you inner double quotes

<?php
$satr=$_POST["satr"];
$soton=$_POST["soton"];
$bg=$_POST["bg"];
echo "<table border=\"1\" style=\"background-color:$bg\">";
for($i=1;&i<=$satr;$i++)
{
    echo "<tr>";
    for($j=1;j<=$soton;$j++)
    {
        echo "<td>$soton</td>";
    }
    echo "</tr>";
}
echo "</table>";
?>

Also look here What is the difference between single-quoted and double-quoted strings in PHP?

Community
  • 1
  • 1
ebadedude
  • 161
  • 8
0

Can you try this, you have used &i in for loop, you need to use $i

    $satr=$_POST["satr"];
    $soton=$_POST["soton"];
    $bg=$_POST["bg"];
    echo ("<table border='1' style='background-color:$bg'>");

    for($i=1;$i<=$satr;$i++)
    {
        echo("<tr>");
        for($j=1;j<=$soton;$j++)
        {
            echo("<td>$soton</td>");
        }

    echo("</tr>");
    }
    echo("</table>");
Krish R
  • 22,583
  • 7
  • 50
  • 59
-2

You are not escaping the quotes in the string. You need to do something like this:

echo ("<table border=\"1\" style=\"background-color:$bg\">");
ChrisF
  • 134,786
  • 31
  • 255
  • 325
PasteBT
  • 2,128
  • 16
  • 17