Jump to content

insert into not working


lacorp

Recommended Posts

$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

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

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')";

 

Archived

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

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.