We help IT Professionals succeed at work.
Get Started

update mutiple record at one time

koochy asked
Last Modified: 2013-12-12
I have a need to an end user to be able to update multiple records from 1 form

I found a multiple update through a search and It pulls the data from the table ok but when I change any of the fields and click submit  it redisplays the orginal information and doesn't update the table. I am probably missing 1 little thing but banging my head on the wall isn't helping .. so I am asking you "the experts" what I am missing!!  thanks in advance ... here is the code I am using

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

$db_host = 'localhost';
$db_user = 'butch';
$db_pass = 'brewser';
$db_name = 'iwe';
$tbl_name="test_mysql"; // Table name

// Connect to server and select databse.
mysql_connect("$db_host", "$db_user", "$db_pass")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

$sql="SELECT * FROM $tbl_name";

// Count table rows
<table width="500" border="0" cellspacing="1" cellpadding="0">
<form name="form1" method="post" action="">
<table width="500" border="0" cellspacing="1" cellpadding="0">

<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>
<td align="center"><?php $id[]=$rows['id']; ?><?php echo $rows['id']; ?></td>
<td align="center"><input name="name[]" type="text" id="name" value="<?php echo $rows['name']; ?>"></td>
<td align="center"><input name="lastname[]" type="text" id="lastname" value="<?php echo $rows['lastname']; ?>"></td>
<td align="center"><input name="email[]" type="text" id="email" value="<?php echo $rows['email']; ?>"></td>
<td colspan="4" align="center"><input type="submit" name="Submit" value="Submit"></td>
// Check if button name "Submit" is active, do this
$sql1="UPDATE $tbl_name SET name='$name[$i]', lastname='$lastname[$i]', email='$email[$i]' WHERE id='$id[$i]'";
echo $sql1;

Watch Question
This problem has been solved!
Unlock 1 Answer and 4 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE