Jump to content

[SOLVED] Need help with MySQL UPDATE syntax


bigdspbandj

Recommended Posts

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
}

?>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.