hosker Posted December 27, 2011 Share Posted December 27, 2011 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> Quote Link to comment https://forums.phpfreaks.com/topic/253892-insertng-data-from-a-form-into-a-mysql-database/ Share on other sites More sharing options...
WebStyles Posted December 27, 2011 Share Posted December 27, 2011 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'); Quote Link to comment https://forums.phpfreaks.com/topic/253892-insertng-data-from-a-form-into-a-mysql-database/#findComment-1301583 Share on other sites More sharing options...
hosker Posted December 27, 2011 Author Share Posted December 27, 2011 Your code worked, thanks. It inserted all the data except for the value that was held in $tournament. However, it displayed that value to the screen and in the email that is sent as well. Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/253892-insertng-data-from-a-form-into-a-mysql-database/#findComment-1301584 Share on other sites More sharing options...
WebStyles Posted December 27, 2011 Share Posted December 27, 2011 maybe the database field cannot take such a value? (just a suggestion, but if your database field type is set as INT, for example, and you try to insert characters, it will not work) Quote Link to comment https://forums.phpfreaks.com/topic/253892-insertng-data-from-a-form-into-a-mysql-database/#findComment-1301585 Share on other sites More sharing options...
litebearer Posted December 27, 2011 Share Posted December 27, 2011 small 'typo'... $tourney = $_REQUEST['tournament']; Quote Link to comment https://forums.phpfreaks.com/topic/253892-insertng-data-from-a-form-into-a-mysql-database/#findComment-1301586 Share on other sites More sharing options...
hosker Posted December 27, 2011 Author Share Posted December 27, 2011 Thanks for pointing out my typo litebearer!! Quote Link to comment https://forums.phpfreaks.com/topic/253892-insertng-data-from-a-form-into-a-mysql-database/#findComment-1301587 Share on other sites More sharing options...
hosker Posted December 27, 2011 Author Share Posted December 27, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/253892-insertng-data-from-a-form-into-a-mysql-database/#findComment-1301591 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.