bigdspbandj Posted January 16, 2008 Share Posted January 16, 2008 I can't seem to find out what's wrong with the syntax: query: $prnSetupSql = "UPDATE ct_jobs SET print_setup = '$printSetup' WHERE id = $job_id"; $prnSetupQuery = mysql_query($prnSetupSql) or die(mysql_error()); error I am getting: 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 'all)' at line 1 I am the value is a string so I put it in the single quotes. For convenience I have posted all of the code below. Please Help. <?php session_start(); //include files and set general variables include 'includes/config.inc.php'; include 'includes/functions.inc.php'; // check for $_GET. If $_GET Check for type // check for $_GET job_id. if invalid redirect to base dir. if (isset($_GET['job_id']) && is_numeric($_GET['job_id'])) { $job_id = $_GET['job_id']; } else { echo 'we have trouble!!!'; } if (isset($_GET['type'])) { // if type 1 if ($_GET['type'] == 1) { $prnSetupConn = dbConnect(); // setup $_POST as variables $printSetup = $_POST['printSetup']; $stockID = $_POST['stock']; // update ct_jobs with print_setup $prnSetupSql = "UPDATE ct_jobs SET print_setup = '$printSetup' WHERE id = $job_id"; $prnSetupQuery = mysql_query($prnSetupSql) or die(mysql_error()); // check ct_print_setup for type 1 record $prnCheckSql = "SELECT id, job_id, type FROM ct_print_setup WHERE type = 1 AND job_id = $job_id"; $prnCheckQuery = mysql_query($prnCheckSql) or die('123123'); $prnCheckNumRows = mysql_num_rows($prnCheckQuery); // if type 1 record exists for job update with data else add new data if ($prnCheckNumRows > 0) { $prnRows = mysql_fetch_assoc($prnCheckQuery); $prnID = $prnRows['id']; $mainPrnSql = "UPDATE ct_print_setup SET stock_id = $stockID WHERE id = $prnID"; $mainPrnSql = mysql_query($mainPrnSql) or die('test'); if (isset($mainPrnQuery)) { header('location: '.$config_basedir.'work-order.php?id='.$job_id.'&prnUpdated=1'); } } else { $mainPrnSql = "INSERT INTO ct_print_setup (job_id, stock_id, type, pg_range) VALUES ($job_id, $stockID, 1, all)"; $mainPrnQuery = mysql_query($mainPrnSql) or die(mysql_error()); // redirect to work order page with $_GET "added" success message if (isset($mainPrnQuery)) { header('location: '.$config_basedir.'work-order.php?id='.$job_id.'&prnAdded=1'); } } // if type 1 record does not exists insert data in to ct_print_setup // redirect to work order page with $_GET "updated" success message } // if type 2 // insert records into ct_print setup // redirect to work order page with $_GET "exception added" success message } ?> Quote Link to comment https://forums.phpfreaks.com/topic/86341-solved-need-help-with-mysql-update-syntax/ Share on other sites More sharing options...
revraz Posted January 16, 2008 Share Posted January 16, 2008 WHERE id = '$job_id'"; Missing single quotes in a few spots. Quote Link to comment https://forums.phpfreaks.com/topic/86341-solved-need-help-with-mysql-update-syntax/#findComment-441169 Share on other sites More sharing options...
bigdspbandj Posted January 16, 2008 Author Share Posted January 16, 2008 I still get the same error. Also I thought single quotes weren't required when the value is numeric. Quote Link to comment https://forums.phpfreaks.com/topic/86341-solved-need-help-with-mysql-update-syntax/#findComment-441171 Share on other sites More sharing options...
PFMaBiSmAd Posted January 16, 2008 Share Posted January 16, 2008 It is actually the following query (the only one containing the word all)- $mainPrnSql = "INSERT INTO ct_print_setup (job_id, stock_id, type, pg_range) VALUES ($job_id, $stockID, 1, all)"; If pg_range is a string data type, all is a string and it should be enclosed in single quotes. Quote Link to comment https://forums.phpfreaks.com/topic/86341-solved-need-help-with-mysql-update-syntax/#findComment-441173 Share on other sites More sharing options...
bigdspbandj Posted January 16, 2008 Author Share Posted January 16, 2008 DOH! Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/86341-solved-need-help-with-mysql-update-syntax/#findComment-441191 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.