Reputation: 975
I want to update multiple rows but not all the rows. Say I have more than 1000 entries. And I want to change country of only 5 entries.
Sl.No. | Name | Country | Occupation
-------+--------+-----------+-----------
22 | Robin | USA | Dancer
36 | Akash | India | Dancer
98 | David | UK | Dancer
502 | Raj | Australia | Dancer
652 | Bob | USA | Dancer
I want to change it to:
Sl.No. | Name | Country | Occupation
-------+--------+-----------+-----------
22 | Robin | Canada | Dancer
36 | Akash | Nepal | Dancer
98 | David | USA | Dancer
502 | Raj | Kong | Dancer
652 | Bob | China | Dancer
My php code to fetch data is:
<form method="post" action"">
<table>
<?php
if(isset($_POST['submit']))
{
$country=$_POST['country'];
mysql_query("update regis set country='".$country."' where name='".$b['name']."'");
}
$a=mysql_query("select * from regis where occupation='Dancer'");
while($b=mysql_fetch_assoc($a))
{ $country=$b['country'];?>
<tr>
<td><?php echo $b['slno'] ?></td>
<td><?php echo $b['name'] ?></td>
<td> <input type="text" name="name" value="<?php echo $country ?>"></td>
<td><?php echo $b['occupation'] ?></td>
</tr>
<?php }?>
</table>
<input type="submit" name="submit" value="Submit">
</form>
Upvotes: 1
Views: 109
Reputation: 4160
You're missing a single quote on this line:
mysql_query("update regis set country='".$country."' where name='".$b['name']");
Should be:
mysql_query("update regis set country='".$country."' where name='".$b['name']"'");
Please provide more details about error and print variables content.
Note: use mysqli or PDO instead of deprecated mysql
Upvotes: 1
Reputation: 2708
If you want to get error issue just error_reporting(E_ALL);
at starting of code. You will get your answer auto.
Their is a simple syntax error foe upload . Just change update query line : e.g
mysql_query("update regis set country='".$country."' where name='".$b['name']."'");
Upvotes: 1