Jump to content


Photo

Updating a Table Problems


  • Please log in to reply
2 replies to this topic

#1 komquat

komquat
  • Members
  • PipPipPip
  • Advanced Member
  • 130 posts
  • LocationHoughton, MI

Posted 11 July 2006 - 09:16 PM

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:
<?
//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;


?>

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.

<?
//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;

?>


#2 ShogunWarrior

ShogunWarrior
  • Members
  • PipPipPip
  • Advanced Member
  • 528 posts
  • LocationIreland

Posted 11 July 2006 - 11:32 PM

You can loop through them and mysql_query for each one.
<a href="http://www.daviddora...nmedia.com/">My New Site/Blog</a> | <a href="http://www.daviddora...m/check/">Check your page for broken links/images/scripts</a>

Zend Certified Engineer
Follow me on Twitter: http://twitter.com/davidd

#3 komquat

komquat
  • Members
  • PipPipPip
  • Advanced Member
  • 130 posts
  • LocationHoughton, MI

Posted 11 July 2006 - 11:58 PM

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.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users