mysqli insert problem

Discussion in 'PHP' started by Schlaften, Sep 30, 2009.

  1. #1
    Hello,
    I'm new here and I need help with inserting values into a database using mysqli. I have been searching for a few days and have found nothing I can use. I receive no errors, but it still doesn't insert into the database.

    
    <?
    include 'connect.php';
    
    $Date = date('jS F Y');
    $sql2 = "INSERT into userinfo (firstname, lastname, email, joined)
    VALUES
    ('$_POST[Firstname]','$_POST[Lastname]','$_POST[email]','$Date')";
    
    
    $result = mysqli_query($conn, $sql2);
    $select = mysqli_query($conn,"select userinfoID from userinfo where firstname = '$_POST[Firstname]' and lastname = '$_POST[Lastname]' and email = '$_POST[email]' and joined = '$Date'");
    
    if($fetch = mysqli_fetch_array($select)){
    $sql = "INSERT into login (username, password, userinfoID)
    VALUES
    ('$_POST[Username]','$_POST[Password]',$fetch[userinfoID])";
    $result = mysqli_query($conn, $sql);
    }
    echo $sql;
    echo $sql2;
    
    if(!$conn){
    	die('Error: ' . mysqli_error($conn));
    }
    ?>
    
    PHP:

     
    Schlaften, Sep 30, 2009 IP
  2. adrevol

    adrevol Active Member

    Messages:
    124
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    58
    #2
    One suggestion ,, Try Debugging your script..

    1. Echo Your SQL Statements
    2. Try executing your Obtained SQL Statements

    Then you will see the exact error
     
    adrevol, Sep 30, 2009 IP
  3. Schlaften

    Schlaften Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Tried that, no errors, everything seems fine. It says it inserted the values in, but in the database, nothing shows up. Thanks though.
     
    Schlaften, Oct 1, 2009 IP
  4. pixmania

    pixmania Peon

    Messages:
    229
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #4
    
    <?
    include 'connect.php';
    
    $Date = date('jS F Y');
    $sql2 = "INSERT INTO userinfo (firstname, lastname, email, joined) VALUES ($_POST['Firstname'],$_POST['Lastname'],$_POST['email'],$Date)";
    
    
    $result = mysqli_query($conn, $sql2);
    $select = mysqli_query($conn,"SELECT * FROM userinfo WHERE firstname = $_POST['Firstname'] and lastname = $_POST['Lastname'] and email = $_POST['email'] and joined = $Date");
    
    if($fetch = mysqli_fetch_array($select)){
    $sql = "INSERT INTO login (username, password, userinfoID) VALUES ($_POST['Username'],$_POST['Password'],$fetch['userinfoID'])";
    $result = mysqli_query($conn, $sql);
    }
    echo $sql;
    echo $sql2;
    
    if(!$conn){
        die('Error: ' . mysqli_error($conn));
    }
    ?>
    
    
    PHP:
    No idea if this will help, its just written slightly different. You could also write your $conn function into the connect.php file, that would help clean up your code.
     
    pixmania, Oct 1, 2009 IP