Jump to content

INsertng data from a form into a mySQL database


hosker

Recommended Posts

I am having difficulty inserting the following codes values into my database. I know that the variables contain a value as I am displaying them on the output screen.

 

 

$link = mysql_connect($db_host,$db_user,$db_pass) or die('Unable to establish a DB connection');

mysql_select_db($db_database,$link);
mysql_query("SET names UTF8");
$usr = $userid;
$golfer = $_REQUEST['golfer'];
$tourney = $_REQUEST['tournament'];
$backup = $_REQUEST['backup'];
date_default_timezone_set('US/Eastern');
$time = date("Y-m-d H:i:s");
$t_id=1; 



mysql_query("INSERT INTO weekly_picks (t_id, tournament, user, player, backup, timestamp) VALUES ('$t_id', '$tournament', '$usr', '$golfer', '$backup', '$time') or die('Error, insert query failed')");

echo $t_id; echo "<br />";
echo $tourney; echo "<br />";
echo $usr; echo "<br />";
echo $golfer; echo "<br />";
echo $backup; echo "<br />";
echo $time; echo "<br />";
echo $userdetail['email']; echo "<br />";

$to = $userdetail['email'];
$subject = "Weekly Tournament Pick for: $tourney";
$message = "This email is to confirm your pick for $tourney has been received.
Your pick is: $golfer.
Your backup pick is: $backup 
The time it was submitted was $time 
Do not reply to this email, the mailbox does not exist. 
Contact me with any issues at [email protected]";

$from = "[email protected]";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
?>

<div>
<p>This is to confirm that your pick has been submitted for the following tournament: <?php echo $tourney; ?>. A confirmation of your pick as also been emailed to you.</p>
<p>Your golfer: <?php echo $golfer; ?></p>
<p>Your backup: <?php echo $backup; ?></p>
<p>Your pick was submitted at: <?php echo $time; ?></p>
</div>

the or die() should not be included in the query....

 

try changing this:

 

mysql_query("INSERT INTO weekly_picks (t_id, tournament, user, player, backup, timestamp) VALUES ('$t_id', '$tournament', '$usr', '$golfer', '$backup', '$time') or die('Error, insert query failed')");

 

to

 

mysql_query("INSERT INTO weekly_picks (t_id, tournament, user, player, backup, timestamp) VALUES ('$t_id', '$tournament', '$usr', '$golfer', '$backup', '$time')",$link) or die('Error, insert query failed');

I just thought of an additional question about inserting data into my database. With the form, I will be having fields disappear based upon times and will allow the user to revise their submission until they no longer can. However, I only want 1 entry per User per tournament. Is that something that is possible?

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.