Jump to content
Sign in to follow this  
dcole.ath.cx

mysql_query die

Recommended Posts

Below is a script that only does the "die" and prints "Error, insert query failed". What could be the cause of this? Did I setup the $query line correctly? I've messed with the single quotes in VALUES, but it didn't seem to be the problem. There is not PHP error. They MySQL DB is working correctly and was tested with another script. Thanks.

$query = "INSERT INTO " . $tablegone[$g] . " (response, preceed) VALUES ('$gone[$g]', '$preceedinglist')";mysql_query($query) or die('Error, insert query failed');

Share this post


Link to post
Share on other sites

Try dying with mysql_error() to show what went wrong

$query = "INSERT INTO " . $tablegone[$g] . " (response, preceed) VALUES ('$gone[$g]', '$preceedinglist')";mysql_query($query) or die('Error: ' . mysql_error());

Share this post


Link to post
Share on other sites

Did you print the query to see what you're actually sending to the database, with all the values filled in?

Share this post


Link to post
Share on other sites

That problem is now worked out... I had a variable that would sometimes be blank and you can't do that with MySQL, so I added an if statement.Now I have a new problem. I have the above code in a FOR loop, as you can tell by the $g variable. But when it writes to the database only the last INSERT has the right string added to the Database, everyone before that is just blank (Not NULL). When I print mysql_query for each INSERT it does have the correct string ready to be inputted. What could be causing this? There are no PHP or MySQL errors.

Share this post


Link to post
Share on other sites

I've done some messing around and it is due to a return character.... but I can't get rid of it with trim! I've tried using \n and a real return, but nothing happen, it's still there.

$new = trim($old, " \t\r\n");
$new = trim($old, ' \t\r\n');
I've also tried rtrim...

Share this post


Link to post
Share on other sites

Try this:

$query = "INSERT INTO " . trim($tablegone[$g]) . " (response, preceed) VALUES ('" . trim($gone[$g]) . "', '" . trim($preceedinglist) . "')";

If there is a newline there, trim will remove it. There's no such thing as a newline that trim won't remove, it will remove any whitespace at the beginning or end of the string. If it's not removing something, then it's not whitespace, you may need to copy your string into a hex editor or something like PSPad to figure out which character it actually is and where it's coming from.

Share this post


Link to post
Share on other sites

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.   Paste as plain text instead

  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.

Loading...
Sign in to follow this  

×
×
  • Create New...