master82 Posted December 23, 2006 Share Posted December 23, 2006 In a form, when a user clicks the submit button the function below runs, however I get the following error:[quote]QUERY 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 '' at line 1Query was SELECT * FROM gangwars where warID=[/quote][code]<?php//...case "viewsurrenders":gang_staff_viewsurrenders();break;//...function gang_staff_viewsurrenders(){global $db,$ir,$c,$userid,$gangdata;if(!isset($_POST['subm'])){print "<form action='yourgang.php?action=staff&act2=viewsurrenders' method='post'>Choose who to accept the surrender from.<br /><input type='hidden' name='subm' value='submit' />Faction: <select name='sur' type='dropdown'>";$wq=$db->query("SELECT s.*,w.* FROM surrenders s LEFT JOIN gangwars w ON s.surWAR=w.warID WHERE surTO={$ir['gang']}");while($r=$db->fetch_row($wq)){if($gangdata['gangID'] == $r['warDECLARER']) { $w="You";$f="warDECLARED"; } else { $w="Them";$f="warDECLARER"; }$ggq=$db->query("SELECT * FROM gangs WHERE gangID=".$r[$f]);$them=$db->fetch_row($ggq);print "<option value='{$r['surID']}'>War vs. {$them['gangNAME']} (Msg: {$r['surMSG']})</option>";}print "</select><br /><input type='submit' value='Accept Surrender' /></form>";}else{$_POST['sur'] = abs((int) $_POST['sur']);$q=$db->query("SELECT surWAR FROM surrenders WHERE surID={$_POST['sur']}");list($_POST['war']) = $db->fetch_row($q);$wq=$db->query("SELECT * FROM gangwars where warID={$_POST['war']}");$r=$db->fetch_row($wq);if($gangdata['gangID'] == $r['warDECLARER']) { $w="You";$f="warDECLARED"; } else { $w="Them";$f="warDECLARER"; }$db->query("DELETE FROM surrenders WHERE surID={$_POST['sur']}");$db->query("DELETE FROM gangwars WHERE warID={$_POST['war']}");$ggq=$db->query("SELECT * FROM gangs WHERE gangID=".$r[$f]);$them=$db->fetch_row($ggq);$event=str_replace("'","''","<a href='gangs.php?action=view&ID={$ir['gang']}'>{$gangdata['gangNAME']}</a> have accepted the surrender from <a href='gangs.php?action=view&ID={$them['gangID']}'>{$them['gangNAME']}</a>, the war is over!");$db->query("INSERT INTO gangevents VALUES('',{$ir['gang']},unix_timestamp(),'$event') , ('',".$r[$f].",unix_timestamp(),'$event')");print "You have accepted surrender, the war is over.";}}//...?>[/code]Any idea whats wrong? I suspect from the error output its something to do with a missing variable (warID)Also I have printed/echo all the lines - and it seems there is no value for the lines after:[code]list($_POST['war']) = $db->fetch_row($q);[/code]Any help would be welcome Quote Link to comment https://forums.phpfreaks.com/topic/31699-solved-function-not-working/ Share on other sites More sharing options...
mansuang Posted December 23, 2006 Share Posted December 23, 2006 Try [code]$wq=$db->query("SELECT * FROM gangwars where warID='{$_POST[war]}'");[/code] Quote Link to comment https://forums.phpfreaks.com/topic/31699-solved-function-not-working/#findComment-146921 Share on other sites More sharing options...
master82 Posted December 24, 2006 Author Share Posted December 24, 2006 No sorry - I think the problem is that $_POST['war'] is not being assigned a value - could be wrong Quote Link to comment https://forums.phpfreaks.com/topic/31699-solved-function-not-working/#findComment-147145 Share on other sites More sharing options...
trq Posted December 24, 2006 Share Posted December 24, 2006 Please format your code in a way which is readable. Most programmers indent code in logical blocks, yours is just a blob of text. Quote Link to comment https://forums.phpfreaks.com/topic/31699-solved-function-not-working/#findComment-147146 Share on other sites More sharing options...
Jessica Posted December 24, 2006 Share Posted December 24, 2006 If you think the $_POST['war'] is empty, then check your form! when you process, doprint_r($_POST) and you will see all posted vars. Quote Link to comment https://forums.phpfreaks.com/topic/31699-solved-function-not-working/#findComment-147154 Share on other sites More sharing options...
marcus Posted December 24, 2006 Share Posted December 24, 2006 Woah, Jesi, never thought I'd see you here. Quote Link to comment https://forums.phpfreaks.com/topic/31699-solved-function-not-working/#findComment-147157 Share on other sites More sharing options...
master82 Posted December 24, 2006 Author Share Posted December 24, 2006 solved - slightly edited the code Quote Link to comment https://forums.phpfreaks.com/topic/31699-solved-function-not-working/#findComment-147158 Share on other sites More sharing options...
Jessica Posted December 24, 2006 Share Posted December 24, 2006 Okay... Quote Link to comment https://forums.phpfreaks.com/topic/31699-solved-function-not-working/#findComment-147159 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.