Jump to content

MySQL Insert statements in PHP


mmophp

Recommended Posts

What could be the reason my MySQL SELECT statements execute but INSERT statements don't? The SQL statements are correct they work on one hosting platform but not another. I looked at the database settings in PHPmyAdmin and for the username and password specified INSERT statements should be allowd. What else could be the reason. Should the username and password for the database be specified separately from the PHPmyAdmin username and password?

Link to comment
Share on other sites

Either the query is incorrect, the user doesn't have permission, or the table structure doesn't match the fields in the query. It's probably best to just check for an error message though, you can use mysql_error to print an error message if a call to mysql_query fails.

Link to comment
Share on other sites

Yes. The MySQL and phpMyAdmin privilages are separate ones (AFAIK). The username which you use to connect to the database needs to have INSERT privilages. I'd suggest you ask your host for assistance if that is the reason.The other possible reason for an INSERT statement not to be executed is the same as any other - invalid query. Yes, it works on one host, but does it work with the same data being inserted and the same charset when connecting to the DB? If either of those is different, there is the possibility of an invalid character getting in there, which would make the query fail. Of course, if you use mysql_real_escape_string(), that can't be it.Can you show us some code? Maybe there is another piece of code failing on that other host and preventing the query from even beginning.

Link to comment
Share on other sites

Either the query is incorrect, the user doesn't have permission, or the table structure doesn't match the fields in the query. It's probably best to just check for an error message though, you can use mysql_error to print an error message if a call to mysql_query fails.
The table structure was wrong. Thanks.
Link to comment
Share on other sites

Yes. The MySQL and phpMyAdmin privilages are separate ones (AFAIK). The username which you use to connect to the database needs to have INSERT privilages. I'd suggest you ask your host for assistance if that is the reason.The other possible reason for an INSERT statement not to be executed is the same as any other - invalid query. Yes, it works on one host, but does it work with the same data being inserted and the same charset when connecting to the DB? If either of those is different, there is the possibility of an invalid character getting in there, which would make the query fail. Of course, if you use mysql_real_escape_string(), that can't be it.Can you show us some code? Maybe there is another piece of code failing on that other host and preventing the query from even beginning.
I found the problem. The table structure had a bug. Thanks.
Link to comment
Share on other sites

Archived

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

×
×
  • Create New...