brianlange Posted April 5, 2011 Share Posted April 5, 2011 I have a mysql insert statement generated with php that is not populating the table. I've echoed the statement and if I copy and paste into phpmyadmin it works fine. The result of the mysql_query function is true. I've emptied the table so there are no primary key conflicts. I've put the statement in a try catch and it does not display a exception. What else can I try? Here's the statement INSERT INTO `wp_term_relationships` (object_id, term_taxonomy_id, term_order) VALUES (1597,83,0) Works absolute fine if I copy and paste into phpmyadmin. Does not populated the table if run through mysql_query Quote Link to comment https://forums.phpfreaks.com/topic/232805-mysql-insert-not-working/ Share on other sites More sharing options...
SamT_ Posted April 5, 2011 Share Posted April 5, 2011 Are you getting any error messages from your PHP page? The query looks correct and you confirmed it by running it in phpMyAdmin. This sounds like a problem with your PHP, paste it here in tags and remove your password from mysql_connect(). Quote Link to comment https://forums.phpfreaks.com/topic/232805-mysql-insert-not-working/#findComment-1197451 Share on other sites More sharing options...
ManiacDan Posted April 5, 2011 Share Posted April 5, 2011 He means to paste it inside [ code ] tags. Also, are you sure you're in the right database on the right server? Your PHPMyAdmin instance is probably running on the local MySQl server, the PHP script could be connecting to another server entirely. -Dan Quote Link to comment https://forums.phpfreaks.com/topic/232805-mysql-insert-not-working/#findComment-1197455 Share on other sites More sharing options...
brianlange Posted April 5, 2011 Author Share Posted April 5, 2011 echo $insert_term_relationship . '<br /><br />'; $result = mysql_query($insert_term_relationship) or die(mysql_error()); echo $result; The result of my echo statement is what I am copy and pasting into phpmyadmin. $result is always equal to 1. Quote Link to comment https://forums.phpfreaks.com/topic/232805-mysql-insert-not-working/#findComment-1197457 Share on other sites More sharing options...
brianlange Posted April 5, 2011 Author Share Posted April 5, 2011 I am on the right server. I am running multiple queries. The first query doesn't enter anything despite returning true from mysql query. The second one inserts correctly. The table has zero rows before running the script so I'm sure what has been entered. Losing my mind here INSERT INTO `wp_term_relationships` (object_id, term_taxonomy_id, term_order) VALUES (1597,83,0) INSERT INTO `wp_term_relationships` (object_id, term_taxonomy_id, term_order) VALUES (1597,77,0) Quote Link to comment https://forums.phpfreaks.com/topic/232805-mysql-insert-not-working/#findComment-1197462 Share on other sites More sharing options...
jcbones Posted April 5, 2011 Share Posted April 5, 2011 Are you inserting them with separate calls to mysql_query(), or are you just delimiting them with a semi-colon, and running one mysql_query() ? Quote Link to comment https://forums.phpfreaks.com/topic/232805-mysql-insert-not-working/#findComment-1197485 Share on other sites More sharing options...
brianlange Posted April 5, 2011 Author Share Posted April 5, 2011 Its within a loop which results in separate calls to mysql_query Quote Link to comment https://forums.phpfreaks.com/topic/232805-mysql-insert-not-working/#findComment-1197496 Share on other sites More sharing options...
brianlange Posted April 5, 2011 Author Share Posted April 5, 2011 I did a repair table and got the record to insert once. Now its back to not working. Inserting through phpmyadmin works fine. I guess I'll look into using a different server... Quote Link to comment https://forums.phpfreaks.com/topic/232805-mysql-insert-not-working/#findComment-1197504 Share on other sites More sharing options...
ManiacDan Posted April 6, 2011 Share Posted April 6, 2011 Show the results for SHOW CREATE TABLE on this table. Did you make sure you only had ONE database and database server? You're not inserting into test and checking production or anything like that? --Dan Quote Link to comment https://forums.phpfreaks.com/topic/232805-mysql-insert-not-working/#findComment-1197744 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.