ricmetal Posted July 12, 2011 Share Posted July 12, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/241768-insert-not-happening/ Share on other sites More sharing options...
ricmetal Posted July 12, 2011 Author Share Posted July 12, 2011 f'kn primary. the id column was not set to primary. Quote Link to comment https://forums.phpfreaks.com/topic/241768-insert-not-happening/#findComment-1241694 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.