EP Posted July 15, 2008 Share Posted July 15, 2008 Hey guys. I need a little help here. I have a program that spits out a text file with a complete INSERT query to insert data into a mysql database. After the text file is updated, this php file is supposed to be run using GET instead of POST so it can take the new info from the file and run the command. I tried to call the file up in a web browser and checked the database but it was not updated. Here is the code: <? mysql_connect("localhost", "root", "password"); mysql_select_db("database"); $file=file_get_contents("output_file.txt"); mysql_query($file); mysql_close(); ?> The final mysql_query result should be something like... mysql_query("INSERT INTO table VALUES ('value1', 'value2', 'value3', 'value4')"); ..because that's what the text file contains. I don't understand what I am doing wrong. Any help would be appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/114821-solved-file_get_contents-help/ Share on other sites More sharing options...
trq Posted July 15, 2008 Share Posted July 15, 2008 Can we see the exact contents of the text file? Quote Link to comment https://forums.phpfreaks.com/topic/114821-solved-file_get_contents-help/#findComment-590384 Share on other sites More sharing options...
EP Posted July 15, 2008 Author Share Posted July 15, 2008 Ok. " INSERT INTO table VALUES ( 'title', 'artist', 'album', '2008/07/15 03:10:17' ) " Quote Link to comment https://forums.phpfreaks.com/topic/114821-solved-file_get_contents-help/#findComment-590385 Share on other sites More sharing options...
trq Posted July 15, 2008 Share Posted July 15, 2008 Remove the surrounding double quotes so the text file simply reads.... INSERT INTO table VALUES ( 'title', 'artist', 'album', '2008/07/15 03:10:17' ) Quote Link to comment https://forums.phpfreaks.com/topic/114821-solved-file_get_contents-help/#findComment-590387 Share on other sites More sharing options...
EP Posted July 15, 2008 Author Share Posted July 15, 2008 Still doesn't work. :'( Quote Link to comment https://forums.phpfreaks.com/topic/114821-solved-file_get_contents-help/#findComment-590399 Share on other sites More sharing options...
trq Posted July 15, 2008 Share Posted July 15, 2008 What does this ouput? <?php mysql_connect("localhost", "root", "password"); mysql_select_db("database"); $sql = file_get_contents("output_file.txt"); if (mysql_query($sql)) { echo "Success"; } else { echo mysql_error() . "<br />$sql"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/114821-solved-file_get_contents-help/#findComment-590407 Share on other sites More sharing options...
EP Posted July 15, 2008 Author Share Posted July 15, 2008 Output: $sql"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/114821-solved-file_get_contents-help/#findComment-590417 Share on other sites More sharing options...
trq Posted July 15, 2008 Share Posted July 15, 2008 Did you use the full <?php as I showed? Quote Link to comment https://forums.phpfreaks.com/topic/114821-solved-file_get_contents-help/#findComment-590418 Share on other sites More sharing options...
EP Posted July 15, 2008 Author Share Posted July 15, 2008 Oops. Ok, it shows success and the database was updated. Thanks alot man. Quote Link to comment https://forums.phpfreaks.com/topic/114821-solved-file_get_contents-help/#findComment-590422 Share on other sites More sharing options...
trq Posted July 15, 2008 Share Posted July 15, 2008 A lesson learnt. Do not use <? tags. Quote Link to comment https://forums.phpfreaks.com/topic/114821-solved-file_get_contents-help/#findComment-590424 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.