ebats Posted November 5, 2008 Share Posted November 5, 2008 I'm coding a php to verify the age over 13 and then enter information into a database. I think I'm pretty close, but it doesn't work every time. <?php $month = $_REQUEST['month']; $day = $_REQUEST['day']; $year = $_REQUEST['year']; $this_day = date(d); $this_month = date(m); $this_year = date(Y); $day_val = $this_day - $day; $month_val = $this_month - $month; $year_val = $this_year - $year; if($year_val <13&&$month_val >= 0&&$day_val >= 0) { header('Location: http://www.ADDRESSTOOYOUNG.html'); } $con = mysql_connect("SERVER","USERNAME","PASSWORD"); if (!$con) { die('Could not connect: ' . mysql_error()); }mysql_select_db("DATABASENAME", $con);$sql="INSERT INTO TABLENAME(FirstName, LastName, email, month, day, year) VALUES ('$_POST[FirstName]','$_POST[LastName]','$_POST','$_POST[month]','$_POST[day]','$_POST[year]')";if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } mysql_close($con); header('Location: http://www.ADDRESSTHANKS.html'); ?> Thanks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/131527-solved-php-newbie-needs-assistance/ Share on other sites More sharing options...
Goldeneye Posted November 5, 2008 Share Posted November 5, 2008 Did you try changing the $_POST variables to $_REQUEST variables? Quote Link to comment https://forums.phpfreaks.com/topic/131527-solved-php-newbie-needs-assistance/#findComment-683099 Share on other sites More sharing options...
ebats Posted November 5, 2008 Author Share Posted November 5, 2008 Not completely familiar with the difference of the variables so forgive me. The html form that's calling the php is submitting the day, month, year elements to the database. so $_POST i think is what I need. the $_REQUEST for the age verification part I'm not too sure about. Quote Link to comment https://forums.phpfreaks.com/topic/131527-solved-php-newbie-needs-assistance/#findComment-683108 Share on other sites More sharing options...
ebats Posted November 5, 2008 Author Share Posted November 5, 2008 Did you try changing the $_POST variables to $_REQUEST variables? Tried it, no dice. The php submits the data to the database despite the age under 13, then if I hit the back button and resubmit, it redirects me to the ADDRESSTOOYOUNG page. Quote Link to comment https://forums.phpfreaks.com/topic/131527-solved-php-newbie-needs-assistance/#findComment-683119 Share on other sites More sharing options...
KevinM1 Posted November 5, 2008 Share Posted November 5, 2008 Not completely familiar with the difference of the variables so forgive me. The html form that's calling the php is submitting the day, month, year elements to the database. so $_POST i think is what I need. the $_REQUEST for the age verification part I'm not too sure about. PHP has several superglobal (read: accessible everywhere in a script) variables: $_GET, which contains data passed into the script via query string and the get method of an HTML form. $_POST, which contains data passed into the script via the post method of an HTML form. $_COOKIE, which contains data passed into the script via a cookie. There's also $_REQUEST, which is a catch-all superglobal. It quite literally holds all data passed to the script by those other methods of data input. So $_POST['someValue'] and $_REQUEST['someValue'] point to the same thing. Quote Link to comment https://forums.phpfreaks.com/topic/131527-solved-php-newbie-needs-assistance/#findComment-683125 Share on other sites More sharing options...
ebats Posted November 5, 2008 Author Share Posted November 5, 2008 Not completely familiar with the difference of the variables so forgive me. The html form that's calling the php is submitting the day, month, year elements to the database. so $_POST i think is what I need. the $_REQUEST for the age verification part I'm not too sure about. PHP has several superglobal (read: accessible everywhere in a script) variables: $_GET, which contains data passed into the script via query string and the get method of an HTML form. $_POST, which contains data passed into the script via the post method of an HTML form. $_COOKIE, which contains data passed into the script via a cookie. There's also $_REQUEST, which is a catch-all superglobal. It quite literally holds all data passed to the script by those other methods of data input. So $_POST['someValue'] and $_REQUEST['someValue'] point to the same thing. Good info thanks! So it's just the under 13 calculation that isn't working properly. Quote Link to comment https://forums.phpfreaks.com/topic/131527-solved-php-newbie-needs-assistance/#findComment-683131 Share on other sites More sharing options...
ebats Posted November 5, 2008 Author Share Posted November 5, 2008 SOLVED. Just had to rearrange the code a bit with an if else statement. <?php $month = $_REQUEST['month']; $day = $_REQUEST['day']; $year = $_REQUEST['year']; $this_day = date(d); $this_month = date(m); $this_year = date(Y); $day_val = $this_day - $day; $month_val = $this_month - $month; $year_val = $this_year - $year; if($year_val >= 13&&$month_val >= 0&&$day_val >= 0) { $con = mysql_connect("SERVER","DATABASE","PASSWORD"); if (!$con) { die('Could not connect: ' . mysql_error()); }mysql_select_db("DATABASE", $con);$sql="INSERT INTO TABLE(FirstName, LastName, email, month, day, year) VALUES ('$_POST[FirstName]','$_POST[LastName]','$_POST','$_POST[month]','$_POST[day]','$_POST[year]')";if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } mysql_close($con); header('Location: http://www.ADDRESSTHANKS.html'); } else { header('Location: http://www.ADDRESSTOOYOUNG.html'); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/131527-solved-php-newbie-needs-assistance/#findComment-683179 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.