Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>As far as I understood, after the user form submission you want to redirect the user to test_update2.php and the problem was that you couldn't simply do that since the headers were already been send. You can't ever use header() method after HTML, because you can't ever get control of the headers after you output some HTML. </p> <p>I fixed your code and tested it out and it was working perfectly.</p> <p>EDITED:</p> <pre><code>&lt;?php $host="localhost"; // Host name $username="root"; // Mysql username $password="root"; // Mysql password $db_name="db_test"; // Database name $tbl_name="test_table"; // Table name // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); // Check if button name "Submit" is active, do this if(isset($_POST['Submit'])) { foreach($_POST['id'] as $id) { $onoff = 0; if (isset($_POST["ONOFF".$id])) { $onoff = 1; } if($onoff == 1) { $sql1="UPDATE ".$tbl_name." SET name='".$_POST["name".$id]."', email='".$_POST["email".$id]."', description='".$_POST["description".$id]."', phone_number='".$_POST["phone_number".$id]."', operation='".$_POST["operation".$id]."', ONOFF='".$onoff."' WHERE id='".$id."'"; } else { $sql1="UPDATE ".$tbl_name." SET ONOFF='".$onoff."' WHERE id='".$id."'"; } $result1=mysql_query($sql1); } } //get data from DB $sql="SELECT * FROM $tbl_name"; $result=mysql_query($sql); // Count table &lt;strong class="highlight"&gt;rows&lt;/strong&gt; $count=mysql_num_rows($result); ?&gt; &lt;strong&gt;Update &lt;strong class="highlight"&gt;multiple&lt;/strong&gt; &lt;strong class="highlight"&gt;rows&lt;/strong&gt; &lt;strong class="highlight"&gt;in&lt;/strong&gt; &lt;strong class="highlight"&gt;mysql&lt;/strong&gt;&lt;/strong&gt;&lt;br&gt; &lt;table width="500" border="0" cellspacing="1" cellpadding="0"&gt; &lt;form name="form1" method="post" action="&lt;? echo $_SERVER['REQUEST_URI']; ?&gt;"&gt; &lt;tr&gt; &lt;td&gt; &lt;table width="500" border="0" cellspacing="1" cellpadding="0"&gt; &lt;tr&gt; &lt;td align="center" bgcolor="#FFFFFF"&gt;&lt;strong&gt;Id&lt;/strong&gt;&lt;/td&gt; &lt;td align="center" bgcolor="#FFFFFF"&gt;&lt;strong&gt;Name&lt;/strong&gt;&lt;/td&gt; &lt;td align="center" bgcolor="#FFFFFF"&gt;&lt;strong&gt;Email&lt;/strong&gt;&lt;/td&gt; &lt;td align="center" bgcolor="#FFFFFF"&gt;&lt;strong&gt;Description&lt;/strong&gt;&lt;/td&gt; &lt;td align="center" bgcolor="#FFFFFF"&gt;&lt;strong&gt;Phone Number&lt;/strong&gt;&lt;/td&gt; &lt;td align="center" bgcolor="#FFFFFF"&gt;&lt;strong&gt;Operation&lt;/strong&gt;&lt;/td&gt; &lt;/tr&gt; &lt;?php while($rows=mysql_fetch_array($result)) { ?&gt; &lt;tr&gt; &lt;td align="center"&gt;&lt;input type="hidden" name="id[]" value="&lt;? echo $rows['id']; ?&gt;" /&gt;&lt;? echo $rows['id']; ?&gt;&lt;/td&gt; &lt;td align="center"&gt;&lt;input name="name&lt;? echo $rows['id']; ?&gt;" type="text" id="name" value="&lt;? echo $rows['name']; ?&gt;"&gt;&lt;/td&gt; &lt;td align="center"&gt;&lt;input name="email&lt;? echo $rows['id']; ?&gt;" type="text" id="email" value="&lt;? echo $rows['email']; ?&gt;"&gt;&lt;/td&gt; &lt;td align="center"&gt;&lt;input name="description&lt;? echo $rows['id']; ?&gt;" type="text" id="description" value="&lt;? echo $rows['description']; ?&gt;"&gt;&lt;/td&gt; &lt;td align="center"&gt;&lt;input name="phone_number&lt;? echo $rows['id']; ?&gt;" type="text" id="phone_number" value="&lt;? echo $rows['phone_number']; ?&gt;"&gt;&lt;/td&gt; &lt;td align="center"&gt;&lt;input name="operation&lt;? echo $rows['id']; ?&gt;" type="text" id="operation" value="&lt;? echo $rows['operation']; ?&gt;"&gt;&lt;/td&gt; &lt;td align="center"&gt;&lt;input name="ONOFF&lt;? echo $rows['id']; ?&gt;" type="checkbox" id="ONOFF" value="1" &lt;?php if ($rows['ONOFF'] ==1) { echo "checked";} else {} ?&gt; &lt;/td&gt; &lt;/tr&gt; &lt;?php } ?&gt; &lt;tr&gt; &lt;td colspan="4" align="center"&gt;&lt;input type="submit" name="Submit" value="Submit"&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/form&gt; &lt;/table&gt; &lt;?php //close mysql connection mysql_close(); ?&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload