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 Link to comment https://forums.phpfreaks.com/topic/90011-solved-insert-query-with-a-where-not-running/ 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. Link to comment https://forums.phpfreaks.com/topic/90011-solved-insert-query-with-a-where-not-running/#findComment-461534 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? Link to comment https://forums.phpfreaks.com/topic/90011-solved-insert-query-with-a-where-not-running/#findComment-461536 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 Link to comment https://forums.phpfreaks.com/topic/90011-solved-insert-query-with-a-where-not-running/#findComment-461537 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? :-\ Link to comment https://forums.phpfreaks.com/topic/90011-solved-insert-query-with-a-where-not-running/#findComment-461541 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! Link to comment https://forums.phpfreaks.com/topic/90011-solved-insert-query-with-a-where-not-running/#findComment-461549 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! Link to comment https://forums.phpfreaks.com/topic/90011-solved-insert-query-with-a-where-not-running/#findComment-461554 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. Link to comment https://forums.phpfreaks.com/topic/90011-solved-insert-query-with-a-where-not-running/#findComment-461565 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 Link to comment https://forums.phpfreaks.com/topic/90011-solved-insert-query-with-a-where-not-running/#findComment-461597 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.