basset Posted March 12, 2010 Share Posted March 12, 2010 Hello, I am getting this error when opening a php page: 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 pilotID= 19' at line 3 Here is the code for the page Im trying to open. From everything I have read, there is a missing ; - but I cant find where it is, if indeed this is the issue. Thank You for your time, Basset <html> <title>Add a Pilot to a Squadron</title> <body> <?php if (!$_COOKIE["auth"] == "0") { //If not Authorized Exit exit; } require('./config.php'); include('./includes/MySQLiAdminConnect.php'); // If There's data passed in then Squad Pilot if ($_POST) { $squadronName = $_POST["squadron_Name"]; $pilotName = $_POST["pilot_Name"]; if ($squadronName == "None") { $squadronID = "null"; } else { // Get Squadron ID $sql = "SELECT squadronID FROM squadrons WHERE squadronName = '".$squadronName."' COLLATE utf8_bin"; $getResults = mysqli_query($mysqliAdmin, $sql) or die(mysqli_error($mysqliAdmin)); if (mysqli_num_rows($getResults) > 0) { while ($row = @mysqli_fetch_array($getResults)) { $squadronID = stripslashes($row["squadronID"]); } mysqli_free_result($getResults); } } // Get Pilot ID $sql = "SELECT pilotID FROM pilots WHERE pilotName = '".$pilotName."' COLLATE utf8_bin"; $getResults = mysqli_query($mysqliAdmin, $sql) or die(mysqli_error($mysqliAdmin)); if (mysqli_num_rows($getResults) > 0) { while ($row = @mysqli_fetch_array($getResults)) { $pilotID = stripslashes($row["pilotID"]); } mysqli_free_result($getResults); $sql = "UPDATE pilots SET squadronID = $squadronID WHERE pilotID= $pilotID"; $getResults = mysqli_query($mysqliAdmin, $sql) or die(mysqli_error($mysqliAdmin)); mysqli_free_result($getResults); } else { // Pilot Did not Exist in Pilots table so add them $sql = "INSERT INTO pilots ( pilotName, ipaddress, country, squadronId ) VALUES ('$pilotName', null, null, $squadronID )"; $getResults = mysqli_query($mysqliAdmin, $sql) or die(mysqli_error($mysqliAdmin)); mysqli_free_result($getResults); } echo "<p><strong>Pilot ( ".$_POST["pilot_Name"]." ) added to Squadron ( ".$_POST["squadron_Name"]." ) </strong></p>"; } else { $squadronName = $_GET["squadron_Name"]; $pilotName = $_POST["pilot_Name"]; } // Get List of Squadrons for Select Box $sql = "SELECT squadronName FROM squadrons ORDER BY squadronName"; $getResults = mysqli_query($mysqliAdmin, $sql) or die(mysqli_error($mysqliAdmin)); if (mysqli_num_rows($getResults) > 0) { echo " <form method=\"post\" action=\"".$_SERVER["PHP_SELF"]."\"> <p>Select a Squadron then enter the Pilot name to Add to it<br/> </p> <p><strong>Squadron Name:</strong><br/> <select name=\"squadron_Name\" defaultSelected=\"None\">"; echo "<option value=\"None\">None</option>"; while ($row = @mysqli_fetch_array($getResults)) { $squadronName = stripslashes($row["squadronName"]); echo "<option value=\"$squadronName\">$squadronName</option>"; } echo "</select>"; mysqli_free_result($getResults); } else { echo "No Squadrons to add a Pilot To"; } //mysqli_close($mysqliAdmin); // Get List of Pilots for Select Box $sql = "SELECT pilotID, pilotName FROM pilots ORDER BY pilotName"; $getResults = mysqli_query($mysqliAdmin, $sql) or die(mysqli_error($mysqliAdmin)); if (mysqli_num_rows($getResults) > 0) { echo " <p><strong>Pilot Name:</strong><br/> <select name=\"pilot_Name\" defaultSelected=\"None\">"; echo "<option value=\"None\">None</option>"; while ($row = @mysqli_fetch_array($getResults)) { $pilotName = stripslashes($row["pilotName"]); echo "<option value=\"$pilotName\">$pilotName</option>"; } echo "</select>"; mysqli_free_result($getResults); echo " <p><input type=\"submit\" name=\"submit\" value=\"Squad Pilot\"></p> </form>"; } else { echo "No Pilots to associate"; } mysqli_close($mysqliAdmin); ?> <SCRIPT type="text/javascript"> function closepopup() { close (); } </SCRIPT> <p><A href="javascript: closepopup()">Close</A></p> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/195024-sql-syntax-error-question/ Share on other sites More sharing options...
PFMaBiSmAd Posted March 12, 2010 Share Posted March 12, 2010 It's likely that the query that is failing is the following one and that $squadronID does not contain anything - $sql = "UPDATE pilots SET squadronID = $squadronID WHERE pilotID= $pilotID"; You should echo out the failed query in your error reporting logic so that you can see if it is what you expect. Quote Link to comment https://forums.phpfreaks.com/topic/195024-sql-syntax-error-question/#findComment-1025242 Share on other sites More sharing options...
basset Posted March 13, 2010 Author Share Posted March 13, 2010 TY for the reply!! Quote Link to comment https://forums.phpfreaks.com/topic/195024-sql-syntax-error-question/#findComment-1025588 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.