Jump to content

UPDATE multiple rows?


jsk1gcc

Recommended Posts

hey can someone advice me on how to make my update script update multiple rows.

 

here's what i've got so far:

update.php

<?php
require('connect.php');

$update = mysql_query("SELECT DISTINCT rideName FROM ride ORDER BY rideName DESC" );
$numrows = mysql_num_rows($update);

echo "<form action='mysql_update.php' method='POST'>
<select name='updateRide' >";


while ($row=mysql_fetch_assoc($update))
{
                        #$rideID = $row ['rideID'];
                        $rideName = $row ['rideName'];
                        #$seatNumber = $row ['seatNumber'];
                        #$time = $row ['time'];
                        #$price = $row ['price'];


echo "<option value='$id'> $rideName </option>";



}
echo "</select>
<input type='text' name='tochange'> 
<input type='submit' name='submit' value='change'>      
</form>";
?>

 

and now the handler script: mysql_update.php

<?php
require ('connect.php');

$updateRide=$_POST['updateRide'];
$tochange=$_POST['tochange'];

if ($updateRide&&$tochange)
{
$change = mysql_query("UPDATE ride SET rideName='$tochange'
WHERE $id='updateRide'");

}

?>


 

 

When I try this I get nothing, no changes. In the table there is 3 distinct rideNames each have more than 20 rows. Is there a way using the drop down box and ext field like i Have to update all of the distinct rideNames in the table?

 

Thanks.

 

 

Link to comment
https://forums.phpfreaks.com/topic/224368-update-multiple-rows/
Share on other sites

I fixed it by myself, no problems. code is here for anyone else who might have the same problem somewhere down the line

 

 

update.php

<?php
require("connect.php");


$extractR = mysql_query("SELECT DISTINCT rideID, rideName FROM ride ORDER BY rideID " );
$numrows = mysql_num_rows($extractR);

echo " Change the ride name: <form action='mysql_update.php' method='POST'>
<select name='ride_name' >";


while ($row=mysql_fetch_assoc($extractR))
{
                        $rideID = $row ['rideID'];
                        $rideName = $row ['rideName'];
                        #$seatNumber = $row ['seatNumber'];
                        #$time = $row ['time'];
                        #$price = $row ['price'];value='$rideID'

echo $row;
echo "<option value='$rideID'> $rideName </option>";

}
echo "</select>
<input type='text' name='tochangeRide'> 
<input type='submit' name='submit' value='change'> 
</form>";
?>

 

 

mysql_update.php

<?php
require ('connect.php');

$ride_name=$_POST['ride_name'];
$tochangeRide=$_POST['tochangeRide'];

if ($ride_name&&$tochangeRide)
{
$changeR = mysql_query("UPDATE ride SET rideName='$tochangeRide'
WHERE rideID='$ride_name'");

}

echo "You have updated the ride name to $tochangeRide";
?>


 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.