Jump to content

Record being inserted twice?


lxndr

Recommended Posts

I'm sure I must be doing something incredibly dumb here but in certain circumstances when I call this particular php program I have written which is intended to insert a single record I find that instead it inserts the same record twice (there's no index field).  I don't know what to make of it, this is the actual code:

 

 

$today = time();                                                                                                                                                                                                                                                                                     

if (BST()==TRUE)  $today = $today + 3600;

$sql = "INSERT INTO stories_views  VALUES ( '$user_name', $rec_id, $today ) ";

$result = mysql_query($sql, $db)  or die(" - Failed More Information:<br><pre>$q</pre><br>Error: " . mysql_error());

 

The field types are as follows:

 

$user_name:  varchar

$rec_id:  int

$today:  int

 

 

It's starting to drive me nuts now so if anyone can suggest what the problem might be it'd be much appreciated.

 

Link to comment
https://forums.phpfreaks.com/topic/75971-record-being-inserted-twice/
Share on other sites

Hmmm...I don't see anything wrong with that chunk of code.

 

You should wrap your variables in quotes within queries.

$sql = "INSERT INTO stories_views  VALUES ( '$user_name', '$rec_id', '$today') ";

 

Is that all the code from that file? If not, could you post more of it?

I can't see the code that well, stick it in between some [ code ] [ /code ] stuff.

 

However, as the recent reply says, try something like this:

 

$sql = "INSERT INTO stories_views (username,rec_id,today) VALUES ( '$user_name', '$rec_id', '$today') ";

 

Where username, rec_id, and today are the corresponding columns you want to add in. It may be something technical and picky o_o

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.