MasterACE14 Posted February 8, 2008 Share Posted February 8, 2008 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 Quote Link to comment Share on other sites More sharing options...
awpti Posted February 8, 2008 Share Posted February 8, 2008 INSERT doesn't take a WHERE. Maybe you need to use UPDATE. Quote Link to comment Share on other sites More sharing options...
MasterACE14 Posted February 8, 2008 Author Share Posted February 8, 2008 hmm, I need to use a Insert, but only "WHERE id='players id' " , is there any other way I can accomplish the same thing? Quote Link to comment Share on other sites More sharing options...
awpti Posted February 8, 2008 Share Posted February 8, 2008 That's now how INSERT works. http://dev.mysql.com/doc/refman/5.0/en/update.html Quote Link to comment Share on other sites More sharing options...
MasterACE14 Posted February 8, 2008 Author Share Posted February 8, 2008 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? :-\ Quote Link to comment Share on other sites More sharing options...
brandensmith1 Posted February 8, 2008 Share Posted February 8, 2008 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! Quote Link to comment Share on other sites More sharing options...
brandensmith1 Posted February 8, 2008 Share Posted February 8, 2008 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! Quote Link to comment Share on other sites More sharing options...
haku Posted February 8, 2008 Share Posted February 8, 2008 any ideas why? That error often arises from an empty response to a mysql request, so when you see it its good to check the syntax of your query. Using the query the poster above me wrote should fix your problem. Quote Link to comment Share on other sites More sharing options...
MasterACE14 Posted February 8, 2008 Author Share Posted February 8, 2008 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! , Thanks for your help mate and thanks for the advice, I will keep the quotes info in mind Regards ACE Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.