Jump to content

Help figuring this out


kenwvs

Recommended Posts

I have a script that for some reason (can't figure it out) it won't update to the database.  When I run the script, it doesn't produce any errors, it goes through like it should, but it just doesn't update.

I have created a form that works properly to create a work order.  Now when a manager looks at it, and adds a purchase order number and comments, it won't add them to the database.

A  couple of things I am not sure it they are related is on the line below, it doesn't show in my editor as being a php code, yet, when I run it, the data is inserted into the form field.  When I just pasted it to this posting, I see it shows up that they are working, so must be in my editor.....not liking something.
There are a number of lines that act like this.  All the lines that use $workorderInfo[] are doing this.
[code]
Unit Starts:<input type="text" value="<?php echo $workorderInfo['Starts']; ?>" size="10" id="Starts">
[/code]

The other thing I am not sure about is if the isset() is set up properly, to work through the form and ultimately submit it to the database.

Here is the complete code.  If you need me to try something, please ask, and I will do my best to get it for you.  I have been looking at this for days and can't figure out what the problem is that it won't update to the DB, I know the DB is set up properly.

[code]
<!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-->
<div id="headerleft"><h1>GE Jenbacher<BR><BR><span class="indent"> Work Order</span><BR></h1><!--Open Left Header-->
</div> <!--Close Left Header-->
<div id="headerright"><a href="#" title="GE Jenbacher">
<img src="leftimage.gif" alt="GE Jenbacher Right Image"
width="205" height="56" border="0" align="right"></a> <!--Open Right Header-->
</div>
</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-->
Developed by Ken Van Someren - 2006<BR><!-- Open Footer -->
Permission must be granted for any and all use<BR>No Guarantees as to the reliability
or suitability of this document is provided.
<!-- Close Footer -->
</div><!-- Close Mainbox -->
<?php
exit();
}
else
{
$Purchase = $_POST["Purchase"];
$Comment = $_POST["Comment"];

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

[/code]
Link to comment
Share on other sites

When you say it wont add them to the database, i can only assume that you mean this query:
mysql_query ("UPDATE `workorder` set Purchase = '$Purchase', Comment = '$Comment' WHERE work = '$Work'")
or die(mysql_error());

Because there is no INSERT query any where.

As far as i can see, your use of isset() is fine, but try this with the query:

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

So you can see what the query is actually doing. There may be no errors in it, but perhaps one of the variables isn't right.
Link to comment
Share on other sites

When I put that in the code, the following line came on the script.  I never had the chance to add comments or anything.  The page with all the form fields never appeared.  You have one page where you key the work order in and it is suppose to return the results from the DB with that invoice number.  I never got to that point, just this line where the info would normally be displayed

[Quote]UPDATE `workorder` set Purchase = '', Comment = '' WHERE work = ''[/quote]
Link to comment
Share on other sites

<!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-->
<div id="headerleft"><h1>GE Jenbacher<BR><BR><span class="indent"> Work Order</span><BR></h1><!--Open Left Header-->
</div> <!--Close Left Header-->
<div id="headerright"><a href="#" title="GE Jenbacher">
<img src="leftimage.gif" alt="GE Jenbacher Right Image"
width="205" height="56" border="0" align="right"></a> <!--Open Right Header-->
</div>
</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-->
Developed by Ken Van Someren - 2006<BR><!-- Open Footer -->
Permission must be granted for any and all use<BR>No Guarantees as to the reliability
or suitability of this document is provided.
<!-- Close Footer -->
</div><!-- Close Mainbox -->
<?php
exit();
}
else
{
$Purchase = $_POST["Purchase"];
$Comment = $_POST["Comment"];

$sql ="UPDATE `workorder` set Purchase = '$Purchase', Comment = '$Comment' WHERE work = '$Work'";
mysql_query($sql)or die(mysql_error());
echo $sql;
}
exit();
?>
<?php
//echo print_r($_POST)
?>
</body>
</html>
Link to comment
Share on other sites

OOPS, sorry

[code]
<!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-->
<div id="headerleft"><h1>GE Jenbacher<BR><BR><span class="indent"> Work Order</span><BR></h1><!--Open Left Header-->
</div> <!--Close Left Header-->
<div id="headerright"><a href="#" title="GE Jenbacher">
<img src="leftimage.gif" alt="GE Jenbacher Right Image"
width="205" height="56" border="0" align="right"></a> <!--Open Right Header-->
</div>
</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-->
Developed by Ken Van Someren - 2006<BR><!-- Open Footer -->
Permission must be granted for any and all use<BR>No Guarantees as to the reliability
or suitability of this document is provided.
<!-- Close Footer -->
</div><!-- Close Mainbox -->
<?php
exit();
}
else
{
$Purchase = $_POST["Purchase"];
$Comment = $_POST["Comment"];

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

[/code]
Link to comment
Share on other sites

A couple of things...did you say that when you go to this page you dont see the form? Make sure you are not just refreshing because you'll probably get the warning that you will be submitting information again(certainly if you are using Firefox or IE). You might have to close your browser and navigate back to the page.

Also, where are you defining $work?
Link to comment
Share on other sites

I load up a login page (html page) and you key in the work order number.  When you press submit, it loads up this page with the data from the workorder number you keyed in.  The following codes are on this  page to define $work. 

[code]$Contact = $_POST['Contact'];[/code]  and then also

[code]$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'");[/code]

Link to comment
Share on other sites

Just a note that before I loaded the line

[code]$sql ="UPDATE `workorder` set Purchase = '$Purchase', Comment = '$Comment' WHERE work = '$Work'";
mysql_query($sql)or die(mysql_error());
echo $sql;[/code] 

when I keyed in a work order number, the form loaded with all the proper data from the DB.

Ken
Link to comment
Share on other sites

$work is the same as the work field form in the form.

When I run the form right now I get that error that says
UPDATE `workorder` set Purchase = '', Comment = '' WHERE work = ''

That is all that appears in the section of the page that would normally have the form.  The form iteself does not appear at all.
Link to comment
Share on other sites

The form that you actually enter the original data in is different from the update form.

The form that you enter the existing work order number is a different form that directs you to this form when you key in the work order number.  So this is the first time this form is opened.
Link to comment
Share on other sites

Form A you start the work order process.........1st form you complete

Form B is the form the manager reviews and assigns a purchase order and comments

Form C is the form where you login to the managers form

So this is how it works:

Employee completed Form A

The Manager completes Form C, which is simply a form field to input the work order # and is automatically sent to Form B, which has all the data from Form A in it, plus 2 additional fields.  One for Purchase Order and one for Manager comments.  These are the two fields that I can't get it to update.  These fields were not on the original form.  Should i be using insert instead of update?
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.