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

Link to comment
Share on other sites

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?  :-\

Link to comment
Share on other sites

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!

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.