Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Nov 2006
    Thanked 0 Times in 0 Posts

    Arrow Where am I going wrong

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

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

    Thanks in advance.


  • #2
    Master Coder
    Join Date
    Jun 2003
    Cottage Grove, Minnesota
    Thanked 1,094 Times in 1,085 Posts
    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?


    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts