...

View Full Version : Where am I going wrong



Chris13
11-28-2006, 08:57 PM
This code does not submit anything to database neither does it show me any error. Just a blank page. Also not sure what does this line if ($_POST['submit']) supposed to carry. Please advice.

if ($_POST['submit']) {

// connect and select the database
$conn = mysql_connect($host, $user, $password) or die(mysql_error());
$db = mysql_select_db($dbName, $conn) or die(mysql_error());

// insert new entry in the database if entry submitted


$fName = $_POST['fName'];
$lName = $_POSR['lName'];
$email = $_POST['email'];
$confEmail = $_POST['confEmail'];
$password = $_POST['password'];
$confirmPassword = $_POST['confirmPassword'];
$address = $_POST['address'];
$city = $_POST['city'];
$state = $_POST['state'];
$postCode = $_POST['postCode'];
$gender = $_POST['gender'];
$profession = $_POST['profession'];
$ageGroup = $_POST['ageGroup'];
$mallPref = $_POST['mallPref'];
$mailConsent = $_POST['mailConsent'];

// insert new entry into database
$sql = "insert data `userdata` (`fName`, `lName`, `email`, `confEmail`, `password`, `confirmPassword`, `address`, `city`, `state`, `postCode`, `gender`, `profession`, `ageGroup`, `mallPref`, `mailConsent`) VALUES ('$fName', '$lName', '$email', '$confEmail', '$password', '$confirmPassword', '$address', '$city', '$state', '$postCode', '$gender', '$profession', '$ageGroup', '$mallPref', '$mailConsent')";

if(mysql_query($sql))
echo("Values inserted successfully");
else
die("Error! Could not insert values".mysql_error());
} // end if new entry posted
?>

Thanks in advance.

Chris

mlseim
11-28-2006, 09:13 PM
I see one typo: $lName = $_POSR['lName'];

On your form, where you have < input type="submit" ... >
you need a name like this:
<input type="submit" name="submit" value="Submit">

Your script will then see a value there and satisfy the if statement.
Because you only see a blank screen, I suspect that's your problem.

Make sure your <form> method="post" ...

If you don't want to worry about POST or GET, change your
PHP script lines from $_POST[ ] to $_REQUEST[ ]
That will take care of any variable submissions.

I also question the single quotes around your variables (the variables
with the dollar signs) ... in your $sql = line. I don't think you need
those there, but maybe it doesn't matter?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum