Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to select different rows from mysql and update them in a single page
    primarykey
    data
    text
    <p>I want to select some rows from sql database . first user should insert two variable that I can select this rows . then in this page there is table that will update this rows but the problem is when I choose this columns without inputs I'm able to update the database but when I want to use input variables it shows the table but it cannot update it . where did I make a mistake ? </p> <p>selecting databse columns without using inputs :</p> <pre><code>&lt;?php include 'mytool.php'; // username and password sent from form $myusername=$_SESSION["mys"]; $host="localhost"; // Host name $username='username'; // Mysql username $password='password'; // Mysql password $db_name="db"; // Database name $tbl_name="test"; // Table name // Connect to server and select database. $link=mysql_connect($host,$username,$password)or die("cannot connect"); $selected=mysql_select_db($db_name,$link)or die("cannot select DB"); $sql="SELECT * FROM $tbl_name where classnum='106' and level='i4' "; $result=mysql_query($sql,$link); $count=mysql_num_rows($result); ?&gt; </code></pre> <p>input variables : </p> <pre><code>&lt;form id="searchform" method="post" dir="rtl" action=""&gt; level :&lt;input name="level" type="text" id="level" /&gt; classnumber :&lt;input name="classnum" type="text" id="classnum" /&gt; &lt;input style="margin-top:10px; margin-left:120px; font-size: 14px; padding: 5px 14px;" type="submit" value="search" name="enter" /&gt; &lt;/form&gt; &lt;?php if(isset($_POST['enter'])){ $sql="SELECT * FROM $tbl_name where classnum='106' and level='i4' "; $result=mysql_query($sql,$link); $count=mysql_num_rows($result); } ?&gt; </code></pre> <p>update table code after code above :</p> <pre><code> &lt;form name="form1" action="" method="POST"&gt; &lt;center&gt; &lt;div&gt; &lt;div align="center" width = 615&gt; &lt;table class="stats" cellspacing="0" width="615" border="1"&gt; &lt;tr&gt; &lt;th width="20" scope="col" &gt;Id&lt;/th&gt; &lt;th width="60" scope="col"&gt;Name&lt;/th&gt; &lt;th width="60" scope="col"&gt;Last Name&lt;/th&gt; &lt;th width="42" scope="col"&gt;Midterm&lt;/th&gt; &lt;th width="54" scope="col"&gt;Class mark&lt;/th&gt; &lt;th width="42" scope="col"&gt;Final Quiz&lt;/th&gt; &lt;th width="54" scope="col"&gt;State&lt;/th&gt; &lt;th width="54" scope="col"&gt;Details&lt;/th&gt; &lt;/tr&gt; &lt;?php while($rows=mysql_fetch_array($result)){ $id[]=$rows['id']; ?&gt; &lt;tr&gt; &lt;td align="center"&gt; &lt;input name="id[]" type="text" id="id" value="&lt;? echo $rows['id']; ?&gt;" &gt; &lt;/td&gt; &lt;td align="center"&gt;&lt;input type="text" name="name[]" id="name" value= "&lt;? echo $rows['name']; ?&gt;" /&gt;&lt;/td&gt; &lt;td align="center"&gt;&lt;input type="text" name="lastname[]" id="lastname" value= "&lt;? echo $rows['lastname']; ?&gt;" /&gt;&lt;/td&gt; &lt;td align="center"&gt;&lt;input type="text" name="midmark[]" id="midmark" /&gt;&lt;/td&gt; &lt;td align="center"&gt;&lt;input type="text" name="classmark[]" id="classmark" /&gt;&lt;/td&gt; &lt;td align="center"&gt;&lt;input type="text" name="finalmark[]" id="finalmark" /&gt;&lt;/td&gt; &lt;td align="center"&gt;&lt;input type="text" name="state[]" id="state" /&gt;&lt;/td&gt; &lt;td align="center"&gt;&lt;input type="text" name="details[]" id="details" /&gt;&lt;/td&gt; &lt;/tr&gt; &lt;?php } ?&gt; &lt;/table&gt; &lt;/div&gt; &lt;input type="submit" value="ثبت" name="Submit" /&gt; &lt;/form&gt; &lt;?php // Check if button name "Submit" is active, do this if(isset($_POST['Submit'])) { for($i=0;$i&lt;$count;$i++) { $sql1=mysql_query(" UPDATE `".$tbl_name."` SET midmark='".$_REQUEST['midmark'][$i]."' , classmark='".$_REQUEST['classmark'][$i]."' , finalmark='".$_REQUEST['finalmark'][$i]."' , state='".$_REQUEST['state'][$i]."' , details='".$_REQUEST['details'][$i]."' WHERE id='".$_REQUEST['id'][$i]."' "); $result1=mysql_query($sql1); } } if($result1){ header("location:results.php"); } mysql_close(); ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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