jsk1gcc Posted January 13, 2011 Share Posted January 13, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/224368-update-multiple-rows/ Share on other sites More sharing options...
jsk1gcc Posted January 14, 2011 Author Share Posted January 14, 2011 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"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/224368-update-multiple-rows/#findComment-1159183 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.