Jump to content


Photo

Syntax Error = Frustration


  • Please log in to reply
15 replies to this topic

#1 kenwvs

kenwvs
  • Members
  • PipPipPip
  • Advanced Member
  • 194 posts

Posted 18 August 2006 - 09:08 PM

I have a feeling the error listed below is just to frustrate people.  I have tried using single quotes, double quotes, no quotes, and also using $Work instead of $Contact (as $Contact=$Work from another page) and I get this same error, regardless of what I am using.

The 08194151 is the work order number that I have keyed in on the previous page, to bring up this page.  This error is coming up as soon as I hit enter, which directs this page to load, with all the data loaded into it.  I don't actually get the page to load with all the data.

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 ' Comment = WHERE Work = '08194151'' at line 1


else
{
$Purchase = $_POST["Purchase"];
$Comment = $_POST["Comment"];

$sql ="UPDATE `workorder` set Purchase = '$Purchase', Comment = '$Comment' WHERE Work = '$Contact'";
mysql_query($sql)or die(mysql_error());
echo $sql;
}

I am not sure if the page is loading, or if I am getting an error before it actually loads....

#2 corbin

corbin
  • Staff Alumni
  • Advanced Member
  • 8,129 posts

Posted 18 August 2006 - 09:13 PM

Hmmm try changing it to
else
{
$Purchase = $_POST["Purchase"];
$Comment = $_POST["Comment"];

$sql ="UPDATE `workorder` set Purchase = '$Purchase', Comment = '$Comment' WHERE Work = '$Contact'";
//mysql_query($sql)or die(mysql_error());
echo $sql;
}

And see what it says $sql is...
Why doesn't anyone ever say hi, hey, or whad up world?

#3 Caesar

Caesar
  • Members
  • PipPipPip
  • Advanced Member
  • 1,025 posts

Posted 18 August 2006 - 09:13 PM

Try:
<?php
$sql ="UPDATE workorder set Purchase = $Purchase, Comment = $Comment WHERE Work = '$Contact'";
?>

Also, make sure you're taking into account case sensitivty.
PHP Ninja

#4 kenwvs

kenwvs
  • Members
  • PipPipPip
  • Advanced Member
  • 194 posts

Posted 18 August 2006 - 09:28 PM

Corbin:

When I change it like you suggested, the syntax error dissappears and I get the line below.  I still don't have the form appear where i can actually input the information for Purchase and Comment before it updates.  Nothing is appearing in the database, so I am assuming nothing is happening as far as updating....

UPDATE `workorder` set Purchase = '', Comment = '' WHERE Work = '08194151'


Caesar:

when I try it like you suggested, I get the same result as above, just without the quotes....where we have removed them.

If I change it back to it was to start with, the syntax error is gone, and I get the same result as above.  If I key in an invalid work number, then I get the same result as above, with the following line also added..

No rows returned from table workorder using ID = ''



#5 Woolf

Woolf
  • Members
  • PipPipPip
  • Advanced Member
  • 41 posts

Posted 18 August 2006 - 09:30 PM

You do already have the Work value of 08194151 in the database, right?

#6 kenwvs

kenwvs
  • Members
  • PipPipPip
  • Advanced Member
  • 194 posts

Posted 18 August 2006 - 09:31 PM

yes, that work order number is in the db.... see my note that i typed as you were typing

#7 Woolf

Woolf
  • Members
  • PipPipPip
  • Advanced Member
  • 41 posts

Posted 18 August 2006 - 09:36 PM

Try doing a test insert just to make sure that the $_POST variables are not messing with you.

else
{
$Purchase = $_POST["Purchase"];
$Comment = $_POST["Comment"];

$sql ="UPDATE `workorder` set Purchase = 'test', Comment = 'test' WHERE Work = '$Contact'";
mysql_query($sql)or die(mysql_error());

}

If that does not work, try replacing $Contact with the actual number, 08194151 ... perhaps the variable is getting lost somewhere.

#8 kenwvs

kenwvs
  • Members
  • PipPipPip
  • Advanced Member
  • 194 posts

Posted 18 August 2006 - 09:39 PM

So you are suggesting that instead of using update, change it to insert?  Am I not going to run into the same problem, where the form itself won't show up on the screen, so I can't input any data?  Right now, when I key in the number, I don't get the form itself, just the comments above.

Ken

#9 Woolf

Woolf
  • Members
  • PipPipPip
  • Advanced Member
  • 41 posts

Posted 18 August 2006 - 09:41 PM

Sorry, I meant try doing a test 'update', using the provided code. (e.g. instead of using the Purchase and Comment variables from $_POST, just try entering random samples to make sure that it will actually update) If it does, it's something wrong with your $_POST variables, if it doesn't, it's something wrong with your query and/or database.

#10 tomfmason

tomfmason
  • Staff Alumni
  • Advanced Member
  • 1,696 posts
  • Locationstealing your wifi

Posted 18 August 2006 - 09:45 PM

try this

$sql ="UPDATE `workorder` SET `purchase` = '$purchase', `comment` = '$comment' WHERE `work` = '$contact'";


I tested something just like this and it worked fine.

Traveling East in search of instruction, and West to propagate the knowledge I have had gained.

current projects: pokersource

My Blog | My Pastebin | PHP Validation class | Backtrack linux


#11 kenwvs

kenwvs
  • Members
  • PipPipPip
  • Advanced Member
  • 194 posts

Posted 18 August 2006 - 09:52 PM

When I replace it with Test, that updates to the DB.

So I am thinking that means there is something wrong with the variables, but, the way it is, there is something wrong elsewhere (I think) cause I can't input any data in for the variable to use, as the form fields itself doesn't come on the screen.

Would it be a problem with this, seeing as the form isn't coming up?

<?php
$query=mysql_query("SELECT Work, Sched, Name, Site, Serial, Hours, Starts, Issue, Severity,
Resolution, Assistance, PartsA, PartsB, PartsC, PartsD, PartsE, PartsF, PartsG, Safety 
FROM workorder WHERE Work='$Contact'");
if (!$query) {
    echo "YOU HAVE AN ERROR IN YOUR QUERY!<br>\n";
    echo mysql_error();
} else {
    $workorderInfo = mysql_fetch_assoc($query);
}
//this is just for testing
if (mysql_num_rows($query) == 0) {
    echo "No rows returned from table workorder using ID = '$Work'<br>\n";
}
?>
<?php
if (!isset($_POST['Submit']))
{
?>

All the form data

else
{
$Purchase = $_POST["Purchase"];
$Comment = $_POST["Comment"];

$sql ="UPDATE `workorder` set Purchase = 'test', Comment = 'test' WHERE Work = '$Contact'";
mysql_query($sql)or die(mysql_error());
echo $sql;
}
exit();


#12 corbin

corbin
  • Staff Alumni
  • Advanced Member
  • 8,129 posts

Posted 18 August 2006 - 09:58 PM

Ummm where is  your form coming from?  I havent seen a form yet...
Why doesn't anyone ever say hi, hey, or whad up world?

#13 kenwvs

kenwvs
  • Members
  • PipPipPip
  • Advanced Member
  • 194 posts

Posted 18 August 2006 - 10:04 PM

Here is how it basically works.

An engine fails and a technician completes a workorder (Page A).  A Manager is notified of this, and goes to a html page (Page B) where they key in the workorder #, which is suppose to bring up    the Manager Form (Page C), which is where he can add comments and a purchase order number, and then update the database.

I have the original form working, and the form where the manager calls up Page C, but I can't get Page C to appear on the screen, and then update to the DB.  The code I supplied in a post earlier is the info from Page C, minus the form itself.  In my editor, if I preview Page C, the form will come up on the screen, but when I try to actually run the codes through, I don't get the form.  Where the form should be, that is where I get the  UPDATE `workorder` set Purchase = '', Comment = '' WHERE Work = '08194151' statement.

Somewhere in this process, the page is coming up properly, and if I do get the page up, and try to input data and then update it, it won't update.

#14 kenwvs

kenwvs
  • Members
  • PipPipPip
  • Advanced Member
  • 194 posts

Posted 18 August 2006 - 10:06 PM

This is the complete code, for Page C, which is the form that should come up with the data in it, and then the manager can add comments and a purchase order #

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>GE Jenbacher</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="ge.css" rel="stylesheet" type="text/css">
<?php
include_once "myconnect.php";
$Contact = $_POST['Contact'];
// GEWOManager.php
?>
</head>
<body>
<div class="clearfix" id="mainbox"><!--Open Mainbox-->
<div id="header"<!--Open Header-->
<?php
include "header.html"//This is an include for all of the Header
?>
</div> <!--Close Header-->
<div id="topnav"><!--Open Top Navigation-->
Manager Update <span class ="sub"><BR> (Assign a Purchase Order) </span>
</div><!--Close Top Navigation -->
<div id="content"><BR><BR><BR> <!--Open Content-->
<?php
$query=mysql_query("SELECT Work, Sched, Name, Site, Serial, Hours, Starts, Issue, Severity,
Resolution, Assistance, PartsA, PartsB, PartsC, PartsD, PartsE, PartsF, PartsG, Safety 
FROM workorder WHERE Work='$Contact'");
if (!$query) {
    echo "YOU HAVE AN ERROR IN YOUR QUERY!<br>\n";
    echo mysql_error();
} else {
    $workorderInfo = mysql_fetch_assoc($query);
}
//this is just for testing
if (mysql_num_rows($query) == 0) {
    echo "No rows returned from table workorder using ID = '$Work'<br>\n";
}
?>
<?php
if (!isset($_POST['Submit']))
{
?>
<form action="" method="post" enctype="multipart/form-data">
<center><div>Purchase Order #:<input type="text" size="12" maxlength="12" name="Purchase"><BR><BR>
<div><B>Manager Comments:<BR><textarea rows="4" name="Comment" cols="80"></textarea>
</div></B><BR><BR>
<div>Work Order Number:<input type="text" value="<?php echo $workorderInfo['Work']; ?>" size="10" id="Work">
Date:<input type="text" value="<?php echo $workorderInfo['Sched']; ?>" size="10" id="Sched">
Technician:<input type="text" value="<?php echo $workorderInfo['Name']; ?> " size="25" id="Name"> <BR><BR>
Site:<input type="text" value="<?php echo $workorderInfo['Site']; ?>" size="20" id="Site">
Unit Serial Number:<input type="text" value="<?php echo $workorderInfo['Serial']; ?>" size="10" id="Serial">
Unit Hours:<input type="text" value="<?php echo $workorderInfo['Hours']; ?>" size="10" id="Hours">
<BR></><BR></>
Unit Starts:<input type="text" value="<?php echo $workorderInfo['Starts']; ?>" size="10" id="Starts">
Severity:<input type="text" value="<?php echo $workorderInfo['Severity']; ?>" size="25" id="Severe">
 Safety:<input type="text" value="<?php echo $workorderInfo['Safety']; ?>" size="25" id="Safety">
</div> <BR>
<div><B>Description of Issue</B><BR>
<textarea id="Issue" rows="4" cols="80"><?php echo mysql_result($query, 0, 'Issue') ?></textarea></div><BR>
<div><B>Possible Resolution</B><BR>
<textarea id="Resolve" rows="4" cols="80"><?php echo mysql_result($query, 0, 'Resolution') ?></textarea></div><BR>
<div><B>List of Parts Required (one part per line)</B>:</div>
<div><input type="textbox" value="<?php echo $workorderInfo['PartsA']; ?>" size="80" maxlength="80" id="PartsA"><BR>
<input type="textbox" value="<?php echo $workorderInfo['PartsB']; ?>" size="80" maxlength="80" id="PartsB"><BR>
<input type="textbox" value="<?php echo $workorderInfo['PartsC']; ?>" size="80" maxlength="80" id="PartsC"><BR>
<input type="textbox" value="<?php echo $workorderInfo['PartsD']; ?>" size="80" maxlength="80" id="PartsD"><BR>
<input type="textbox" value="<?php echo $workorderInfo['PartsE']; ?>" size="80" maxlength="80" id="PartsE"><BR>
<input type="textbox" value="<?php echo $workorderInfo['PartsF']; ?>" size="80" maxlength="80" id="PartsF"><BR>
<input type="textbox" value="<?php echo $workorderInfo['PartsG']; ?>" size="80" maxlength="80" id="PartsG"><BR>
</div><BR>
<div><B>Request for Assistance:<BR>
<textarea id="Assist" rows="4" cols="80"><?php echo mysql_result($query, 0, 'Assistance') ?></textarea></div><BR>
<div><center><B>The Following people were advised of this Work Order:<BR>
<?php
$result = mysql_query("SELECT * FROM employees") or die(mysql_error());
echo "<select name='Tech'multiple>";
while($row=mysql_fetch_array($result))
{
  echo"<option>$row[Name]</option>";
}
  echo"</select>";
?></select><BR><BR><BR>
<div><input type="submit" name="Submit" value="Update Work Order"><BR><BR><BR><BR></center>
<input type="hidden" name="Contact" value="<?php echo $_POST['Contact']; ?>" />
</form>
</div>

</div><!--Close Content-->
<div id="footer"><!--Open Footer-->
<?php
include "footer.html"
?>
 <!-- Close Footer -->
</div><!-- Close Mainbox -->
<?php
//exit();
}
 else
{
$Purchase = $_POST["Purchase"];
$Comment = $_POST["Comment"];

$sql ="UPDATE `workorder` set Purchase = 'test', Comment = 'test' WHERE Work = '$Contact'";
mysql_query($sql)or die(mysql_error());
echo $sql;
}
exit();
?>
<?php
//echo print_r($_POST)
?>
</body>
</html>


#15 kenwvs

kenwvs
  • Members
  • PipPipPip
  • Advanced Member
  • 194 posts

Posted 18 August 2006 - 11:27 PM

I think I have determined why the form wasn't showing.  I had the !isset() code instead of a isset().  I can get the form to show up, but I still am not getting it to update.  If I replace the variable with TEST and it updates to the DB, would that mean i have a problem with the variable statement somewhere in the coding?

#16 kenwvs

kenwvs
  • Members
  • PipPipPip
  • Advanced Member
  • 194 posts

Posted 18 August 2006 - 11:35 PM

When I remove the !isset() and replace it with the isset() the form appears, but it won't update to the DB.  When I have the !isset() command, it won't show the form, but the DB will update.  Any idea as to what I should start looking at changing to get this working.  It appears as if everything is backwards.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users