0

For some reason my php code isnt writing my variables into my mysql database.

Everything works up until the comment "dies here"

<?php
$name = ucwords($_POST['name']);
$sex = ucwords($_POST['sex']);
$age = intval($_POST['age']);
$email = $_POST['email'];

//DB ACCESS
$db = mysql_connect("localhost", "root", "root");
mysql_select_db("namedb", $db);
//DB ACCESS

if ($sex != 'M' && $sex != 'F') {

echo "Please go back and enter either M or F for 'Sex' <br />";
echo "<a href='index.html'>Back</a>";
die;
}

if (is_int($age) != yes) {
echo "Please enter a number for your age. <br />";
echo "<a href='index.html'>Back</a>";
die;
}

$query = "INSERT INTO people (age, name, email, sex) VALUES($age, $name, $email, $sex)";
mysql_query($query) or die ("Error Updating DB"); //DIES HERE
echo "Thanks $name, we've added you to our database.";

?>

My database is all set up, I have no idea why it isn't sending the data to the database. Here's a picture of the mySQL mysql

Thanks for the help.

Aaron W.
  • 9,254
  • 2
  • 34
  • 45

2 Answers2

3
$query = "INSERT INTO people (age, name, email, sex) VALUES('$age', '$name', '$email', '$sex')";

I don't support mysql_*

Dejan Marjanović
  • 19,244
  • 7
  • 52
  • 66
0

You should use this

  if (!is_int($age)){
       echo "Please enter a number for your age. <br />";
       echo "<a href='index.html'>Back</a>";
       die;
}

It's cleaner and probably more effective since is_int() returns a true or false statement and the if (is_int) basically means if (is_int($foo == true).