lacorp Posted October 19, 2008 Share Posted October 19, 2008 $sql=mysql_query("INSERT INTO topics (ID_BOARD, numReplies, numViews, ID_MEMBER_STARTED, ID_MEMBER_UPDATED, temp) VALUES ('".$top1['ID_BOARD']."', '".$top1['numReplies']."', '".$top1['numViews']."', '".$top1['ID_MEMBER_STARTED']."', '".$top1['ID_MEMBER_UPDATED']."', '1')"); if (!mysql_query($sql,$aef)) { die('Error: ' . mysql_error()); } When I run my program I get Error: Query was empty Any help? Thank you, Lacorp Link to comment https://forums.phpfreaks.com/topic/129102-insert-into-not-working/ Share on other sites More sharing options...
tendrousbeastie Posted October 19, 2008 Share Posted October 19, 2008 Hi, You are running the query twice, anbd the second time is probably what's generating the error. Your line 1 seems correct - you are running the SQL query and storing the result in the $sql variable. As I'm sure you know PHP doesn't store the results as an array or as directly accessible data, rather it stores a resource identifier, which can be passed to other php function to access the data. In your line 3 you are running another mysql_query, but this time you are passing it the $sql resource identifier generated from line 1, rather than an actual query. It is this that is generating the error. On line 3 you could perhaps do something like: if (!is_resource($sql)) or maybe: if (mysql_error() != '') or maybe both, either of which would execute the conditional die command if the query had failed. Hope this helps Link to comment https://forums.phpfreaks.com/topic/129102-insert-into-not-working/#findComment-669314 Share on other sites More sharing options...
Barand Posted October 19, 2008 Share Posted October 19, 2008 just change first line to $sql="INSERT INTO topics (ID_BOARD, numReplies, numViews, ID_MEMBER_STARTED, ID_MEMBER_UPDATED, temp) VALUES ('".$top1['ID_BOARD']."', '".$top1['numReplies']."', '".$top1['numViews']."', '".$top1['ID_MEMBER_STARTED']."', '".$top1['ID_MEMBER_UPDATED']."', '1')"; Link to comment https://forums.phpfreaks.com/topic/129102-insert-into-not-working/#findComment-669396 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.