0

Let see, who will solve this problem before i can... Problem is that values are getting update but in response, it is not showing the update values back on page.

<strong>Update multiple rows in mysql</strong><br>

<?php
$host="localhost"; // Host name
$username="root"; // Mysql username
$password=""; // Mysql password
$db_name="newdb"; // Database name
$tbl_name="web"; // 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");

$sql="SELECT * FROM $tbl_name";
$result=mysql_query($sql);

// Count table rows
$count=mysql_num_rows($result);
?>
<table width="500" border="0" cellspacing="1" cellpadding="0">
<form name="form1" method="get" action="">
<tr>
<td>
<table width="500" border="0" cellspacing="1" cellpadding="0">


<tr>
<td align="center"><strong>Id</strong></td>
<td align="center"><strong>Name</strong></td>
<td align="center"><strong>Lastname</strong></td>
<td align="center"><strong>Email</strong></td>
</tr>
<?php
while($rows=mysql_fetch_array($result)){
?>
<tr>
<td align="center"><input name="id[]" type="text" id="name" value="<?php echo $id[]=$rows['id']; ?>"></td>
<td align="center"><input name="name[]" type="text" id="name" value="<?php echo $name[]=$rows['name']; ?>"></td>
<td align="center"><input name="lastname[]" type="text" id="lastname" value="<?php echo $lastname[]=$rows['lastname']; ?>"></td>
<td align="center"><input name="email[]" type="text" id="email" value="<?php echo $email[]=$rows['email']; ?>"></td>
</tr>
<?php
}
echo "<hr><br>";

echo $count,"<br>";
// Check if button name "Submit" is active, do this
if(Submit)
{

echo $id[$i]=$_GET['id'],"<br>" ;
echo $name=$_GET['name'],"<br>" ;
echo $lastname[$i]=$_GET['lastname'],"<br>" ;
echo $email[$i]=$_GET['email'],"<br><hr>" ;

for($i=0;$i<$count;$i++)
{

echo "Updation start","<br>";
$sql1="UPDATE $tbl_name SET name='$name[$i]', lastname='$lastname[$i]', email='$email[$i]' WHERE id='$id[$i]'";
$result1=mysql_query($sql1);
}
}

if($result1){
echo "Done";
header("location:update_multiple.php");
}
mysql_close();

?>
<tr>
<td colspan="4" align="center"><input type="Submit" name="Submit" value="Submit"></td>
</tr>
</table>
</td>
</tr>
</form>
</table>

<?php
?>
1
Contributor
2
Replies
3
Views
7 Years
Discussion Span
Last Post by atullalit91
0

It shows the values updated on second click, we need updated on a single click.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.