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 xxxxxxx@xxxxxxx.com";

$from = "noreply@chubstersgcc.com";
$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>

Link to comment
Share on other sites

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');

Link to comment
Share on other sites

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?

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.