Jump to content

Updating a Table Problems


komquat

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]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.