Insert statement randomly stopped working

All values going in have been echo’d and seem to be workign properly.

  $insert= mysqli_query($connection, "INSERT into Articles(ArticleID, ArticleDate, ArticleTags, ArticleTitle, ArticleName, ArticleURL, ArticleContent) VALUES(null, '".$articleDate."', '".$articleTags."', '".$articleTitle."', '".$articleName."', '".$articleURL."', '".$articleContent."')");

However, when I do.

$lastID = mysqli_insert_id($connection);

That’s inserted into a page that I make with this new information. That comes up as 0. Presumably no value whatsoever. That insert statement isn’t inserting anymore. No clue why. Could a fresh pair of eyes look at this? I’m getting no errors.

Edit: Wait I did just upgrade from 5.2 on my server to 5.4. Any chance that had anything to do with it?!

Wow, it was.

So why does my script fail when I go to 5.4 apposed to 5.2?!

With queries I prefer to make them far easier to read:


$sql =   "
  INSERT into Articles
  (
    ArticleID, 
    ArticleDate, 
    ArticleTags, 
    ArticleTitle, 
    ArticleName, 
    ArticleURL, 
    ArticleContent
  ) 
  VALUES
  (
    null, 
    '" .$ArticleDate    ."', 
    '" .$articleTags    ."', 
    '" .$articleTitle   ."', 
    '" .$articleName    ."', 
    '" .$articleURL     ."', 
    '" .$articleContent ."'
  )
";
// echo $sql; die;

$insert = mysqli_query( $connection, $sql );

# echo mysqli_error($connection); die;

Also with ArticleID is it set to auto-increment?

Yup, it is auto_increment.

Anyone have any clue why this fails? It seems to just not insert. Echoing the values shows they are there.

Have you tried inserting and ommitting ArticleID?

Edit:

What error is returned?

What does the table schema look like? eg. if a field has a limit does the Insert fail the restrictions

*probably not, but I have a feeling the Date is the culprit

Weird, I remove the ArticleID field/null and the insert worked.

I put it back though, just to confirm that was the issue, however it still inserted as well.

It’s working now?! Sigh…

1 Like

I’m thinking maybe the null is a problem with auto-increment.

Maybe “” instead?
Or maybe explicitly specify the fields?

Why would the PHP version have anything to do with the database though? The database has been unaffected.

I don’t know about PHP versions.
But my db code with inserts has always left out the auto increment field and worked.

eg. with a table like
id auto-increment
something varchar

Set something whatever

has always worked without id in the Insert query

I was just reading that article on sqlite3 basic commands, and noticed that did the same there too.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.