Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.

Join them; it only takes a minute:

Sign up
Join the Stack Overflow community to:
  1. Ask programming questions
  2. Answer and help your peers
  3. Get recognized for your expertise

I'm wondering how to insert multiple values into a database.

Below is my idea, however nothing is being added to the database.

I return the variables above (email, serial, title) successfully. And i also connect to the database successfully.

The values just don't add to the database.

I get the values from an iOS device and send _POST them.

$email = $_POST['email'];
$serial = $_POST['serial'];
$title = $_POST['title'];

After i get the values by using the above code. I use echo to ensure they have values.

Now I try to add them to the database:

  //Query Check
        $assessorEmail = mysqli_query($connection, "SELECT ace_id,email_address FROM assessorID WHERE email_address = '$email'");
        if (mysqli_num_rows($assessorEmail) == 0) {

            echo " Its go time add it to the databse.";

            //It is unqiue so add it to the database
            mysqli_query($connection,"INSERT INTO assessorID (email_address, serial_code, title)
            VALUES ('$email','$serial','$title')");

        } else {

            die(UnregisteredAssessor . ". Already Exists");

        }

Any ideas ?

share|improve this question
    
@Mihai I'm counting 3, I've only been doing this for a day so if I'm still incorrect... – Ryan Jun 25 '14 at 15:20
    
My bad, check if the values are set you might have a NOT NULL column. – Mihai Jun 25 '14 at 15:21
    
Which message are you getting? "Its go time add it to the databse."? Or "Already Exists"? – bloodyKnuckles Jun 25 '14 at 15:34

Since you're using mysqli, I'd instead do a prepared statement

if($stmt = mysqli_prepare($connection, "INSERT INTO assessorID (email_adress, serial_code, title) VALUES (?, ?, ?)"))
{
    mysqli_stmt_bind_param($stmt, "sss", $email, $serial, $title);
    mysqli_stmt_execute($stmt);
    mysqli_stmt_close($stmt);
}

This is of course using procedural style as you did above. This will ensure it's a safe entry you're making as well.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.