genius Posted July 9, 2009 Share Posted July 9, 2009 I've searched everywhere for an answer but am at a loss: Here's my query: $query = "INSERT INTO `" . $database" . "`.`" . $table . "` ( `key_id` ) VALUES ( '" . $_SESSION["key_id"] . "' )"; mysql_db_query($database, $query) or die("Failed Query of " . $query); From PHP I get: "Failed Query of INSERT INTO... etc" in phpMyAdmin, works fine. What am I missing? Quote Link to comment https://forums.phpfreaks.com/topic/165324-basic-sql-query-works-in-phpmyadmin-but-not-php/ Share on other sites More sharing options...
trq Posted July 9, 2009 Share Posted July 9, 2009 What is the output of mysql_error ? Quote Link to comment https://forums.phpfreaks.com/topic/165324-basic-sql-query-works-in-phpmyadmin-but-not-php/#findComment-871848 Share on other sites More sharing options...
genius Posted July 10, 2009 Author Share Posted July 10, 2009 Simply: "Failed Query of..." and then lists the query as above. If there was some phpMyAdmin error I'd list that but it works fine in phpMyAdmin. to be exact: Failed Query of INSERT INTO `gallery`.`images` ( `key_id` ) VALUES ( '342' )"; Quote Link to comment https://forums.phpfreaks.com/topic/165324-basic-sql-query-works-in-phpmyadmin-but-not-php/#findComment-872614 Share on other sites More sharing options...
trq Posted July 10, 2009 Share Posted July 10, 2009 Again, what is the out of mysql_error? Quote Link to comment https://forums.phpfreaks.com/topic/165324-basic-sql-query-works-in-phpmyadmin-but-not-php/#findComment-872624 Share on other sites More sharing options...
kickstart Posted July 10, 2009 Share Posted July 10, 2009 Hi Seems strange that the error message showing the query includes the closing quote and semi colon. All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/165324-basic-sql-query-works-in-phpmyadmin-but-not-php/#findComment-872685 Share on other sites More sharing options...
aschk Posted July 10, 2009 Share Posted July 10, 2009 This is an antequated function now. You should be using mysql_query() instead. Nevertheless try this instead: <?php $query = "INSERT INTO {$database}.{$table}(`key_id`) VALUES ('%s')"; mysql_db_query($database, sprintf($query,mysql_real_escape_string($_SESSION["key_id"]))) or die("Failed Query of " .$query); ?> Quote Link to comment https://forums.phpfreaks.com/topic/165324-basic-sql-query-works-in-phpmyadmin-but-not-php/#findComment-872735 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.