Jump to content

Archived

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

komquat

Updating a Table Problems

Recommended Posts

I am having a problem when updating a table.  I am calling multiple rows and adding data to it, but mysql only handles 1 row updates at a time, how can I use php to update all the rows at once.

Thanks for the help

Current Code:
[code=php:0]
<?
//Start Session
session_start();

//Validate User
if ($_SESSION[valid] != "yes") {
header("Location: http://www.andybourdeau.com/nascar/");
exit;
}

include("include/connection.php");

$p_name = 'n_';
$p_name .= $_POST[tag];
$driver_name = 'd_';
$driver_name .= $_POST[tag];
$driver_name_1 = 'd_';
$driver_name_1 .= $_POST[tag];
$points = 'p_';
$points .= $_POST[tag];

// Query
$sql_drivers = "
SELECT fantasy_id, Week, $driver_name, $points
FROM nascar_second
ORDER BY fantasy_id
";

$qry_edit_drivers = mysql_query($sql_drivers, $connection) or die ("Could not Execute query.");

//Create Form Block
$display_block = "
<form method='post' action='admin_show_update_driver.php'>
<table border='0'>
<tr>
<th>Week</th>
<th>Driver</th>
<th>Points</th>
</tr>";


while ($drivers = mysql_fetch_array($qry_edit_drivers)) {
$fantasy_id = $drivers[fantasy_id];
$week = $drivers[Week];
$d_name = $drivers[$driver_name];
$points = $info[$points];

$display_block .= "
<tr>
<td>$week</td>
<td><input type='text' name='d_name' value='$d_name' size='30'>
<input type='hidden' name='fantasy_id' value='$fantasy_id'></td>
<input type='hidden' name='driver_name_1' value='$driver_name_1'></td>
<td><input type='text' name='points' value='$points' size='3'></td>
</tr>";

}

$display_block .= "
</table>
<br>
<input type='submit' name='submit' value='Edit Driver Info'>
</form>
<br>
";

echo $display_block;


?>
[/code]

The above is the code to generate the current selections and I am able to make changes here.

the next code is where the update will take place, but can not get it to work.  Any help is greatly appreciated.

[code=php:0]
<?
//Session Starting
session_start();

if ($_SESSION[valid] != "yes") {
header("Location:http://www.andybourdeau.com/");
exit;
}

include("include/connection.php");

// Query
$sql = "
UPDATE nascar_second SET
$_POST[driver_name_1] = '$_POST[d_name]'
        WHERE fantasy_id = '$_POST[fantasy_id]'
";

$result = mysql_query($sql, $connection) or die ("Could not Execute Update query. Reason: ".mysql_error());

$display_block = "
Completed";

echo $display_block;

?>
[/code]

Share this post


Link to post
Share on other sites
I have no idea how to start, the variables are only recording the last value in the original Loop.  I can not get it to bring all values from the first page to the second.

Share this post


Link to post
Share on other sites

×

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.