0

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 ?

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

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.