Jump to content

[SOLVED] Insert query with a WHERE not running...


MasterACE14

Recommended Posts

Hi,

 

I've been trying to get this mysql_query() working, it is a INSERT, but with a WHERE, I'm getting Sql errors because of the WHERE, i'm not sure if its a problem with how I have put the WHERE in, or the way I have put the Variables in.

 

here's my error:

Updating your log

 

Error:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE `id`='1'' at line 1

 

and here's my code:

<?php
@mysql_query("INSERT INTO `cf_log` (player_id,type,importance,time,message) VALUES ('$player_accountid','$type_you','$importance','$time','$message_you') WHERE `id`='$player_accountid'") or die('Query:<br /> Updating your log <br /><br />Error:<br />' . mysql_error());

 

any help is greatly appreciated!  :)

 

Regards ACE

right, I got that soughted, thanks  :)

 

I got another question.

 

I have this code:

<?php
// the query is line 78
$log_read = mysql_query("SELECT * FROM `cf_log` WHERE player_id = " . $player_accountid . ", id = " . $_POST['id'] . " LIMIT 1");

		while($row = mysql_fetch_array($log_read)) {

 

and I am getting this error:

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/ace/public_html/conflictingforces/lib/log.php on line 78

 

any ideas why?  :-\

in

$log_read = mysql_query("SELECT * FROM `cf_log` WHERE player_id = " . $player_accountid . ", id = " . $_POST['id'] . " LIMIT 1");

 

If you are using just a regular variable you do not need ".." around it you can just do '$player_accountid' <-single quotes

If it were a a variable with a ['something'] connected to it like a Session[], Cookie[], or in your while loop a row[] you would do ' ".$row['whatever']." '

Hope that helps!

 

Forgot to mention this! Try changing your code to...

$log_read = mysql_query("SELECT * FROM `cf_log` WHERE player_id = '$player_accountid' AND id = ' ".$_POST['id']." ' LIMIT 1");

 

and it should work. Good Luck!

 

 

thats done the trick!  :D , Thanks for your help mate  ;) and thanks for the advice, I will keep the quotes info in mind  :)

 

Regards ACE

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.