Jump to content

Can't post to database


BelowZero

Recommended Posts

I know this should be easy...

 

I have several text input boxes where I enter data to be sent to one column of my database.

[while($row = mysql_fetch_array( $result )) 
{
$i=1;
if ($row['game_id']='$i')
{
echo "<tr>";
echo "<td>"; echo $row['date'];
echo "</td><td>"; echo $row['team_name'];
echo "</td><td>"; echo $row['owner'];
echo "</td><td>";
echo "<input type='text' size='4' name='result[]'>";
echo "</td></tr>";

Not every box has a value so my array will end up with several numbers and several "blanks".

I echoed the array using

$result = ("$_POST[result]");

and all the values are returned as expected.

 

Now I need to UPDATE the "pt_spread" column in the database inserting all the values (even the blank values).

 

I tried the following but can't get it to actually post anything into the database.

<?php	

header("Location: admin_main_entry.php");

include("opendatabase.php");

$result = ("$_POST[result]");
foreach ($result as $spread)
{
$sql = "
UPDATE schedule 
SET pt_spread = '$spread'
WHERE week_id = '$weekID'" ;

mysql_query($sql);
}

mysql_close($con)
?>

Can anyone show me the correct way to do this? Thanks.

Link to comment
https://forums.phpfreaks.com/topic/230385-cant-post-to-database/
Share on other sites

Well, you're redirecting the user before the rest of the code can execute, have you tried running it without that header() function? Just to make sure the row inserts into the db?  If it works after that you should put the header() code after the insert code has processed.

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.