Jump to content

mysql_query die


dcole.ath.cx

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');
Link to comment
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());

Link to comment
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.

Link to comment
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...
Link to comment
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.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...