Jump to content

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/131527-solved-php-newbie-needs-assistance/
Share on other sites

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.

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.

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.

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

}

 

 

 

 

 

?>

 

 

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.