jeff5656 Posted July 22, 2009 Share Posted July 22, 2009 I get "Invalid query: 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 15" Here is the entire code (not long): I cant seem to find the error! <?php include "connectdb.php"; $check1_date = date("Y-m-d", strtotime($_POST['check1_date'])); $check2_date = date("Y-m-d", strtotime($_POST['check2_date'])); $check3_date = date("Y-m-d", strtotime($_POST['check3_date'])); $tp_date = date("Y-m-d", strtotime($_POST['tp_date'])); $sql = "UPDATE tx SET patient = '" . $_POST['patient'] . "', mrn = '" . $_POST['mrn'] . "', check1 = '" . $_POST['check1'] . "', check2 = '" . $_POST['check2'] . "', check3 = '" . $_POST['check3'] . "', comments = '" . $_POST['comments'] . "', check1_date = '$check1_date', check2_date = '$check2_date', check3_date = '$check3_date', signoff_status = '" . $_POST['signoff_status'] . "', tp_date = '$tp_date' WHERE id_incr = ".$_POST['id_incr'].""; if (isset($sql) && !empty($sql)) { $result = mysql_query($sql) or die ("Invalid query: " . mysql_error()); } header("Location: displayactive.php"); ?> Link to comment https://forums.phpfreaks.com/topic/167035-invalid-query-you-have-an-error-in-your-sql-syntax/ Share on other sites More sharing options...
9three Posted July 22, 2009 Share Posted July 22, 2009 In your if statement do this: echo $sql; Does that query look correct? Link to comment https://forums.phpfreaks.com/topic/167035-invalid-query-you-have-an-error-in-your-sql-syntax/#findComment-880703 Share on other sites More sharing options...
ldougherty Posted July 22, 2009 Share Posted July 22, 2009 Try updating your query as follows.. $sql = "UPDATE tx SET patient = $_POST['patient'], mrn = $_POST['mrn'], check1 = $_POST['check1'], check2 = $_POST['check2'], check3 = $_POST['check3'], comments = $_POST['comments'], check1_date = '$check1_date', check2_date = '$check2_date', check3_date = '$check3_date', signoff_status = $_POST['signoff_status'], tp_date = '$tp_date' WHERE id_incr = $_POST['id_incr']"; Link to comment https://forums.phpfreaks.com/topic/167035-invalid-query-you-have-an-error-in-your-sql-syntax/#findComment-880710 Share on other sites More sharing options...
jeff5656 Posted July 22, 2009 Author Share Posted July 22, 2009 Thanks. The problem was I forgot to bring id_incr over from the form as a hidden POST. The echo of sql helped me figure that out. Thanks Link to comment https://forums.phpfreaks.com/topic/167035-invalid-query-you-have-an-error-in-your-sql-syntax/#findComment-880714 Share on other sites More sharing options...
jeff5656 Posted July 22, 2009 Author Share Posted July 22, 2009 To ldougherty: that is a much cleaner code thanks! Link to comment https://forums.phpfreaks.com/topic/167035-invalid-query-you-have-an-error-in-your-sql-syntax/#findComment-880715 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.