Jump to content

INSERT not happening


ricmetal

Recommended Posts

hi guys

i am trying to insert a new row in a table with

if ($stmt = $mysqli->prepare("INSERT INTO photographers (id) VALUES (?)")) {

my photographers table has an id column, which is not incrementable and is an integer.

the value passed to the SELECT is also an integer. (i've double checked and using intval() ).

now, i can't get this row to be inserted! everything i can think and know of is working, db connections, etc. such, that if i change the value to be inserted, (and the column to insert to), the insert works. for instance, if i insert a string in the email column, the insert occurs.

what can i check to see why the id integer won't insert?

 

here is an excerpt of the code i am working on:

// The following insert works fine and yields the id created through the insert (auto incremented)
if ($stmt = $mysqli->prepare("INSERT INTO users (id, user_email, user_pwd, intro_text) VALUES (NULL, ?, ?, ?)")) {
    $stmt->bind_param('sss', $email, $md5pass, $introText);
    $email = $_POST['email'];// this is fetched and treated elsewhere, just here for consistency
    $md5pass = substr(md5($_POST['pass2']), 0, 32);
    $introText = substr($_POST['intro_text'], 0, 500);
    $stmt->execute();
    $newIdString = $stmt->insert_id;
    $newId = intval($newIdString);
    $stmt->close();

        // Insert new user into photographers table. This is where the insert doesn't happen.
        // The commented out lines will work if i run those instead.
        if ($stmt = $mysqli->prepare("INSERT INTO photographers (id) VALUES (?)")) {
    // if ($stmt = $mysqli->prepare("INSERT INTO photographers (user_email) VALUES (?)")) {
            $stmt->bind_param('i', $newId);
        // $stmt->bind_param('s', $email);
            $stmt->execute();
            echo $newId;
            $stmt->close();
            $mysqli->close();

 

what can i check to make this work?

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.