PDA

View Full Version : Problem updating records


brettpower
01-31-2007, 03:40 PM
Hello.
I am having trouble updating records in my database, however, I can find nothing at all wrong with my code. I have been at it for a few hours now, so I may just be overlooking something really small!

No errors are returned.

Here is the first part of my code
<!-- ESTABLISH CONNECTION WITH DATABASE -->
<?php require_once('../Connections/CONNECT.php'); ?>
<?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;

switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) {
$updateSQL = sprintf("UPDATE sr SET name=%s, phone=%s, email=%s, location=%s, description=%s, status=%s, owner=%s, `time`=%s, notes=%s WHERE id=%s",
GetSQLValueString($_POST['name'], "text"),
GetSQLValueString($_POST['phone'], "text"),
GetSQLValueString($_POST['email'], "text"),
GetSQLValueString($_POST['location'], "text"),
GetSQLValueString($_POST['description'], "text"),
GetSQLValueString($_POST['status'], "text"),
GetSQLValueString($_POST['owner'], "text"),
GetSQLValueString($_POST['time'], "text"),
GetSQLValueString($_POST['notes'], "text"),
GetSQLValueString($_POST['id'], "int"));

mysql_select_db($database_CONNECT, $CONNECT);
$Result1 = mysql_query($updateSQL, $CONNECT) or die(mysql_error());

$updateGoTo = "index.php";
if (isset($_SERVER['QUERY_STRING'])) {
$updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
$updateGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $updateGoTo));
}
//RETRIEVE URL VARIABLE FOR DATABASE/ECHO CONSTRAINTS
$first = $_GET['first'];
//CONNECT TO AND QUERY SERVICE REQUEST DATABASE
mysql_select_db($database_CONNECT, $CONNECT);
$query_UpdateView = "SELECT * FROM sr WHERE owner = '$first'";
$UpdateView = mysql_query($query_UpdateView, $CONNECT) or die(mysql_error());
$row_UpdateView = mysql_fetch_assoc($UpdateView);
$totalRows_UpdateView = mysql_num_rows($UpdateView);

// UN-USED CODE

//mysql_select_db($database_CONNECT, $CONNECT);
//$query_Users = "SELECT * FROM users WHERE first = '$first'";
//$Users = mysql_query($query_Users, $CONNECT) or die(mysql_error());
//$row_Users = mysql_fetch_assoc($Users);
//$totalRows_Users = mysql_num_rows($Users);

//mysql_select_db($database_CONNECT, $CONNECT);
//$query_Status = "SELECT * FROM STATUS";
//$Status = mysql_query($query_Status, $CONNECT) or die(mysql_error());
//$row_Status = mysql_fetch_assoc($Status);
//$totalRows_Status = mysql_num_rows($Status);

//PULLS ONLY UNASSIGNED SERVICE REQUESTS
mysql_select_db($database_CONNECT, $CONNECT);
$query_TriageView = "SELECT * FROM sr WHERE owner ='UNASSIGNED'";
$TriageView = mysql_query($query_TriageView, $CONNECT) or die(mysql_error());
$row_TriageView = mysql_fetch_assoc($TriageView);
$totalRows_TriageView = mysql_num_rows($TriageView);

//PULLS ONLY BRETT'S SERVICE REQUESTS
mysql_select_db($database_CONNECT, $CONNECT);
$query_BrettView = "SELECT * FROM sr WHERE owner = 'Brett'";
$BrettView = mysql_query($query_BrettView, $CONNECT) or die(mysql_error());
$row_BrettView = mysql_fetch_assoc($BrettView);
$totalRows_BrettView = mysql_num_rows($BrettView);

//PULLS ONLY BRUCE'S SERVICE REQUESTS
mysql_select_db($database_CONNECT, $CONNECT);
$query_BruceView = "SELECT * FROM sr WHERE owner = 'Bruce'";
$BruceView = mysql_query($query_BruceView, $CONNECT) or die(mysql_error());
$row_BruceView = mysql_fetch_assoc($BruceView);
$totalRows_BruceView = mysql_num_rows($BruceView);

//PULLS ONLY GARY'S SERVICE REQUESTS
mysql_select_db($database_CONNECT, $CONNECT);
$query_GaryView = "SELECT * FROM sr WHERE owner = 'Gary'";
$GaryView = mysql_query($query_GaryView, $CONNECT) or die(mysql_error());
$row_GaryView = mysql_fetch_assoc($GaryView);
$totalRows_GaryView = mysql_num_rows($GaryView);

//PULLS ONLY VICTOR'S SERVICE REQUESTS
mysql_select_db($database_CONNECT, $CONNECT);
$query_VictorView = "SELECT * FROM sr WHERE owner = 'Victor'";
$VictorView = mysql_query($query_VictorView, $CONNECT) or die(mysql_error());
$row_VictorView = mysql_fetch_assoc($VictorView);
$totalRows_VictorView = mysql_num_rows($VictorView);
?>

brettpower
01-31-2007, 03:41 PM
Here is the second part of my code:

<!-- BEGIN HTML PORTION -->

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<style type="text/css">
<!--
body {
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
}
.style1 {color: #666666}
.style9 {font-family: Geneva, Arial, Helvetica, sans-serif; font-size: 12px; }
.style10 {font-size: 12px}
.style12 {font-family: Geneva, Arial, Helvetica, sans-serif; font-size: 12px; font-weight: bold; color: #FF0000; }
-->
</style></head>

<body>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="44%" background="../img/top_repeat.gif"><img src="../img/top_logo.png" width="466" height="98" /></td>
<td width="56%" background="../img/top_repeat.gif">&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
</table>
<table width="100%" border="0" cellpadding="5" cellspacing="0">
<tr>
<td><div align="center" class="style12"><?php echo $totalRows_TriageView ?> </div></td>
<td><div align="center" class="style12"><?php echo $totalRows_BrettView ?> </div></td>
<td><div align="center" class="style12"><?php echo $totalRows_BruceView ?> </div></td>
<td><div align="center" class="style12"><?php echo $totalRows_GaryView ?> </div></td>
<td><div align="center" class="style12"><?php echo $totalRows_VictorView ?> </div></td>
</tr>
<tr>
<td width="20%"><div align="center"><a href="index.php?first=UNASSIGNED"><img src="../img/triage.png" alt="f" width="150" height="25" border="0" /></a></div></td>
<td width="20%"><div align="center"><a href="index.php?first=Brett"><img src="../img/brett.png" alt="f" width="150" height="25" border="0" /></a></div></td>
<td width="20%"><div align="center"><a href="index.php?first=Bruce"><img src="../img/bruce.png" alt="f" width="150" height="25" border="0" /></a></div></td>
<td width="20%"><div align="center"><a href="index.php?first=Gary"><img src="../img/gary.png" alt="f" width="150" height="25" border="0" /></a></div></td>
<td width="20%"><div align="center"><a href="index.php?first=Victor"><img src="../img/victor.png" alt="f" width="150" height="25" border="0" /></a></div></td>
</tr>
</table>
<p>&nbsp;</p>

<form method="post" name="form1" action="<?php echo $editFormAction; ?>">
<?php do { ?>
<table align="center" cellspacing="0" bgcolor="#EEEEEE">
<tr valign="baseline">
<td width="72" align="right" nowrap bgcolor="#CCCCCC"><span class="style9">Id:</span></td>
<td bgcolor="#CCCCCC"><span class="style9"><?php echo $row_UpdateView['id']; ?> / <?php echo $row_UpdateView['owner']; ?></span></td>
<td bgcolor="#CCCCCC"><div align="center" class="style9"><?php echo $row_UpdateView['time']; ?></div></td>
</tr>
<tr valign="baseline">
<td align="right" nowrap bgcolor="#EEEEEE"><span class="style9">Name:</span></td>
<td width="284" bgcolor="#EEEEEE"><span class="style9"><?php echo $row_UpdateView['name']; ?></span></td>
<td width="320" rowspan="7" bgcolor="#EEEEEE"><span class="style9">ISSUE NOTES:
<textarea name="notes" cols="45" rows="12" id="notes"><?php echo $row_UpdateView['notes']; ?></textarea>
</span></td>
</tr>
<tr valign="baseline">
<td align="right" nowrap bgcolor="#EEEEEE"><span class="style9">Phone:</span></td>
<td bgcolor="#EEEEEE"><span class="style9"><?php echo $row_UpdateView['phone']; ?></span></td>
</tr>
<tr valign="baseline">
<td align="right" nowrap bgcolor="#EEEEEE"><span class="style9">Email:</span></td>
<td bgcolor="#EEEEEE"><span class="style9"><?php echo $row_UpdateView['email']; ?></span></td>
</tr>
<tr valign="baseline">
<td align="right" nowrap bgcolor="#EEEEEE"><span class="style9">Location:</span></td>
<td bgcolor="#EEEEEE"><span class="style9"><?php echo $row_UpdateView['location']; ?></span></td>
</tr>
<tr valign="baseline">
<td colspan="2" align="right" valign="top" nowrap bgcolor="#EEEEEE"><span class="style10"></span></td>
</tr>

<tr valign="baseline">
<td align="right" nowrap bgcolor="#EEEEEE"><span class="style9">:</span></td>
<td bgcolor="#EEEEEE"><span class="style9">
<input type="text" name="status" value="<?php echo $row_UpdateView['status']; ?>" size="10" />
</span></td>
</tr>
<tr valign="baseline">
<td colspan="2" align="right" nowrap bgcolor="#EEEEEE"><span class="style9">
<label>
<textarea name="description" cols="45" rows="5"><?php echo $row_UpdateView['description']; ?></textarea>
</label>
</span></td>
</tr>


<tr valign="baseline">
<td align="right" nowrap bgcolor="#EEEEEE">&nbsp;</td>
<td bgcolor="#EEEEEE">&nbsp;</td>
<td bgcolor="#EEEEEE"><span class="style9">Assigned to:
<label>
<input name="owner" type="text" id="owner" value="<?php echo $row_UpdateView['owner']; ?>" />
</label>
<input name="time" type="hidden" id="time" value="<?php echo $row_UpdateView['time']; ?>" />
<input name="email" type="hidden" id="email" value="<?php echo $row_UpdateView['email']; ?>" />
<input name="phone" type="hidden" id="phone" value="<?php echo $row_UpdateView['phone']; ?>" />
<input name="name" type="hidden" id="name" value="<?php echo $row_UpdateView['name']; ?>" />
<input name="location" type="hidden" id="location" value="<?php echo $row_UpdateView['location']; ?>" />
</span></td>
</tr>
<tr valign="baseline">
<td align="right" nowrap bgcolor="#EEEEEE"><span class="style10"></span></td>
<td colspan="2" bgcolor="#EEEEEE"><input type="submit" value="Update Issue"></td>
</tr>
<tr valign="baseline">
<td colspan="3" align="right" nowrap><span class="style1"></span>
<hr /> <span class="style1"></span></td>
</tr>
<tr valign="baseline">
<td colspan="3" align="right" nowrap bgcolor="#FFFFFF">&nbsp;</td>
</tr>
</table>
<br />
<?php } while ($row_UpdateView = mysql_fetch_assoc($UpdateView)); ?><input type="hidden" name="MM_update" value="form1">
</form>
<p>&nbsp;</p>
</body>
</html>
<?php
mysql_free_result($UpdateView);

//mysql_free_result($Users);

//mysql_free_result($Status);

mysql_free_result($TriageView);

mysql_free_result($BrettView);

mysql_free_result($BruceView);

mysql_free_result($GaryView);

mysql_free_result($VictorView);
?>

davidj
01-31-2007, 05:35 PM
first of all add an echo to the update statement to see if whats going in

look for this below ... see the $updateSQL variable. Add an echo before it like i have done;


if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) {

echo $updateSQL = sprintf("UPDATE sr SET name=%s, phone=%s, email=%s, location=%s, description=%s, status=%s, owner=%s, `time`=%s, notes=%s WHERE id=%s",
GetSQLValueString($_POST['name'], "text"),
GetSQLValueString($_POST['phone'], "text"),
GetSQLValueString($_POST['email'], "text"),
GetSQLValueString($_POST['location'], "text"),
GetSQLValueString($_POST['description'], "text"),
GetSQLValueString($_POST['status'], "text"),
GetSQLValueString($_POST['owner'], "text"),
GetSQLValueString($_POST['time'], "text"),
GetSQLValueString($_POST['notes'], "text"),
GetSQLValueString($_POST['id'], "int"));



now perform your update as normal

copy and paste the result in this post.
It will return something like...

UPDATE sr SET name=david, phone=123345, email=david@msn.com

brettpower
01-31-2007, 06:23 PM
Done. Thanks for the tip.

It appears that the root of the problem is that the ID field is not being carried through.

Check it out....
UPDATE sr SET name='vera cooper', phone='386-615-1998-325', email='vcooper@ACCUMEN.NET', location='PC-ADMIN', description='I have no contracts for my e-mails. Can Gary please come over and help.cc', status='OPEN', `time`='Wednesday January 31st 2007 09:04 AM', notes=NULL WHERE id=NULL
Warning: Cannot modify header information - headers already sent by (output started at /home/accumen/www/computerguy/admin/index.php:43) in /home/accumen/www/computerguy/admin/index.php on line 53

davidj
01-31-2007, 06:34 PM
yep thats your problem

you need to find out how your passing the ID var

i see your using post as a method which would require a field called ID but i cant see one in your form

brettpower
01-31-2007, 06:39 PM
I have a hidden field down the page for the ID var.

I am going to stare at this for a bit and see what I can figure out....thanks for the help so far!

davidj
01-31-2007, 06:41 PM
view the source of the page when your running it to see if this field is getting populated with the var id...

brettpower
01-31-2007, 07:04 PM
View source tells me that everything should be just fine. All fields are populated correctly.

Back to the code.....

brettpower
01-31-2007, 07:07 PM
I am willing to bet the problem is and has been right in front of my face the whole time!

davidj
01-31-2007, 07:18 PM
i have just viewed source and all your hidden fields are empty including the ID??

brettpower
01-31-2007, 07:21 PM
Weird. This is what i get when I view source. Did you get the PM I sent you?

UPDATE sr SET name='vera cooper', phone='386-615-1998-325', email='vcooper@ACCUMEN.NET', location='PC-ADMIN', description='I have no contracts for my e-mails. Can Gary please come over and help...', status='OPEN', `time`='Wednesday January 31st 2007 09:04 AM', notes=NULL WHERE 'id'=NULL<br />
<b>Warning</b>: Cannot modify header information - headers already sent by (output started at /home/accumen/www/computerguy/admin/index.php:43) in <b>/home/accumen/www/computerguy/admin/index.php</b> on line <b>53</b><br />
<!-- BEGIN HTML PORTION -->

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<style type="text/css">
<!--
body {
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
}
.style1 {color: #666666}
.style9 {font-family: Geneva, Arial, Helvetica, sans-serif; font-size: 12px; }
.style10 {font-size: 12px}
.style12 {font-family: Geneva, Arial, Helvetica, sans-serif; font-size: 12px; font-weight: bold; color: #FF0000; }
-->
</style></head>

<body>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="44%" background="../img/top_repeat.gif"><img src="../img/top_logo.png" width="466" height="98" /></td>
<td width="56%" background="../img/top_repeat.gif">&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
</table>
<table width="100%" border="0" cellpadding="5" cellspacing="0">
<tr>
<td><div align="center" class="style12">0</div></td>
<td><div align="center" class="style12">0</div></td>
<td><div align="center" class="style12">2</div></td>
<td><div align="center" class="style12">1</div></td>
<td><div align="center" class="style12">0</div></td>
</tr>
<tr>
<td width="20%"><div align="center"><a href="index.php?first=UNASSIGNED"><img src="../img/triage.png" alt="f" width="150" height="25" border="0" /></a></div></td>
<td width="20%"><div align="center"><a href="index.php?first=Brett"><img src="../img/brett.png" alt="f" width="150" height="25" border="0" /></a></div></td>
<td width="20%"><div align="center"><a href="index.php?first=Bruce"><img src="../img/bruce.png" alt="f" width="150" height="25" border="0" /></a></div></td>
<td width="20%"><div align="center"><a href="index.php?first=Gary"><img src="../img/gary.png" alt="f" width="150" height="25" border="0" /></a></div></td>
<td width="20%"><div align="center"><a href="index.php?first=Victor"><img src="../img/victor.png" alt="f" width="150" height="25" border="0" /></a></div></td>
</tr>
</table>
<p>&nbsp;</p>

<form method="post" name="form1" action="/admin/index.php?first=Gary">
<table width="600" align="center" cellspacing="0" bgcolor="#EEEEEE">
<tr valign="baseline">
<td width="72" align="right" nowrap bgcolor="#CCCCCC"><span class="style9">Issue ID :</span></td>
<td bgcolor="#CCCCCC"><span class="style9">35 / Gary</span></td>
<td bgcolor="#CCCCCC"><div align="center" class="style9">Wednesday January 31st 2007 09:04 AM</div></td>
</tr>
<tr valign="baseline">
<td align="right" nowrap bgcolor="#EEEEEE"><span class="style9">Name:</span></td>
<td width="284" bgcolor="#EEEEEE"><span class="style9">vera cooper</span></td>
<td width="320" rowspan="7" bgcolor="#EEEEEE"><span class="style9">ISSUE NOTES:
<textarea name="notes" cols="35" rows="12" id="notes"></textarea>
</span></td>
</tr>
<tr valign="baseline">
<td align="right" nowrap bgcolor="#EEEEEE"><span class="style9">Phone:</span></td>
<td bgcolor="#EEEEEE"><span class="style9">386-615-1998-325</span></td>
</tr>
<tr valign="baseline">
<td align="right" nowrap bgcolor="#EEEEEE"><span class="style9">Email:</span></td>
<td bgcolor="#EEEEEE"><span class="style9">vcooper@ACCUMEN.NET</span></td>
</tr>
<tr valign="baseline">
<td align="right" nowrap bgcolor="#EEEEEE"><span class="style9">Location:</span></td>
<td bgcolor="#EEEEEE"><span class="style9">PC-ADMIN</span></td>
</tr>
<tr valign="baseline">
<td colspan="2" align="right" valign="top" nowrap bgcolor="#EEEEEE"><span class="style10"><span class="style9">
<input name="id" type="hidden" id="id" value="35" />
<input name="time" type="hidden" id="time" value="Wednesday January 31st 2007 09:04 AM" />
<input name="email" type="hidden" id="email" value="vcooper@ACCUMEN.NET" />
<input name="phone" type="hidden" id="phone" value="386-615-1998-325" />
<input name="name" type="hidden" id="name" value="vera cooper" />
<input name="location" type="hidden" id="location" value="PC-ADMIN" />
</span></span></td>
</tr>

<tr valign="baseline">
<td align="right" nowrap bgcolor="#EEEEEE"><span class="style9">Status:</span></td>
<td bgcolor="#EEEEEE"><span class="style9">
<input type="text" name="status" value="OPEN" size="10" />
</span></td>
</tr>
<tr valign="baseline">
<td colspan="2" align="right" nowrap bgcolor="#EEEEEE"><span class="style9">
</span><span class="style9">
<label>
</label>
</span>
<label><div align="left">
<span class="style9">
<textarea name="description" cols="40" rows="5">I have no contracts for my e-mails. Can Gary please come over and help.</textarea>
</span>
<div align="center"></div>
</div>
</label>
<span class="style9"></span><span class="style9"> </span></td>
</tr>

<tr valign="baseline">
<td align="right" nowrap bgcolor="#EEEEEE"><span class="style10"></span></td>
<td colspan="2" bgcolor="#EEEEEE"><input type="submit" value="Update Issue"></td>
</tr>
<tr valign="baseline">
<td colspan="3" align="right" nowrap><span class="style1"></span>
<hr /> <span class="style1"></span></td>
</tr>
<tr valign="baseline">
<td colspan="3" align="right" nowrap bgcolor="#FFFFFF">&nbsp;</td>
</tr>
</table>
<br />
<input type="hidden" name="MM_update" value="form1">
</form>
<p>&nbsp;</p>
</body>
</html>

davidj
01-31-2007, 07:22 PM
yes

i was mistaken

i see it now

brettpower
01-31-2007, 07:24 PM
No problem!

davidj
01-31-2007, 07:29 PM
its working!!

the problem is your logic is wrong

you have 1 form wrapped around your loop so when you submit you are posting from every field including the repeating fields which are writing over the one you want to edit

Pseudo code...

<form>
do loop {
field 1
field 2
field 3

field1
field2
field3

etc

davidj
01-31-2007, 07:32 PM
try sticking your do{ loop outside your form tag

brettpower
01-31-2007, 07:47 PM
I knew it was obvious. Right there in front of me. Oh, well. Thanks for the help. Now onto tracking down the following...

"Warning: Cannot modify header information - headers already sent by (output started at /home/accumen/www/computerguy/admin/index.php:45) in /home/accumen/www/computerguy/admin/index.php on line 55" error.


Maybe some white space somewhere....

davidj
01-31-2007, 07:48 PM
something is echo-ing before the HTML is being sent

davidj
01-31-2007, 07:50 PM
also make sure the PHP is at the top of the page with no spaces or blank lines...

just like you said

davidj
01-31-2007, 08:01 PM
oh nearly forgot...

welcome to the forum brett

brettpower
01-31-2007, 08:05 PM
Thanks, David.

Not sure what is going on here, but the header error is, I believe, now the only problem that is keeping the database from being updated. I can't find any white space anywhere, and there are no echo statements pre the HTML.

davidj
01-31-2007, 08:08 PM
post the entire code from the page

brettpower
01-31-2007, 08:20 PM
Here it is. I hope your eyes are working better than mine!

<?php require_once('../Connections/CONNECT.php'); ?>
<?php function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;

switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) {
echo $updateSQL = sprintf("UPDATE sr SET name=%s, phone=%s, email=%s, location=%s, description=%s, status=%s, time=%s, notes=%s WHERE 'id'=%s",
GetSQLValueString($_POST['name'], "text"),
GetSQLValueString($_POST['phone'], "text"),
GetSQLValueString($_POST['email'], "text"),
GetSQLValueString($_POST['location'], "text"),
GetSQLValueString($_POST['description'], "text"),
GetSQLValueString($_POST['status'], "text"),
GetSQLValueString($_POST['time'], "text"),
GetSQLValueString($_POST['notes'], "text"),
GetSQLValueString($_POST['id'], "int"));

mysql_select_db($database_CONNECT, $CONNECT);
$Result1 = mysql_query($updateSQL, $CONNECT) or die(mysql_error());

$updateGoTo = "../admin/index.php";
if (isset($_SERVER['QUERY_STRING'])) {
$updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
$updateGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $updateGoTo));
}
//RETRIEVE URL VARIABLE FOR DATABASE/ECHO CONSTRAINTS
$tech = $_GET['tech'];
//CONNECT TO AND QUERY SERVICE REQUEST DATABASE
mysql_select_db($database_CONNECT, $CONNECT);
$query_UpdateView = "SELECT * FROM sr WHERE owner = '$tech'";
$UpdateView = mysql_query($query_UpdateView, $CONNECT) or die(mysql_error());
$row_UpdateView = mysql_fetch_assoc($UpdateView);
$totalRows_UpdateView = mysql_num_rows($UpdateView);

// UN-USED CODE

//mysql_select_db($database_CONNECT, $CONNECT);
//$query_Users = "SELECT * FROM users WHERE first = '$first'";
//$Users = mysql_query($query_Users, $CONNECT) or die(mysql_error());
//$row_Users = mysql_fetch_assoc($Users);
//$totalRows_Users = mysql_num_rows($Users);

//mysql_select_db($database_CONNECT, $CONNECT);
//$query_Status = "SELECT * FROM STATUS";
//$Status = mysql_query($query_Status, $CONNECT) or die(mysql_error());
//$row_Status = mysql_fetch_assoc($Status);
//$totalRows_Status = mysql_num_rows($Status);

//PULLS ONLY UNASSIGNED SERVICE REQUESTS
mysql_select_db($database_CONNECT, $CONNECT);
$query_TriageView = "SELECT * FROM sr WHERE owner ='UNASSIGNED'";
$TriageView = mysql_query($query_TriageView, $CONNECT) or die(mysql_error());
$row_TriageView = mysql_fetch_assoc($TriageView);
$totalRows_TriageView = mysql_num_rows($TriageView);

//PULLS ONLY BRETT'S SERVICE REQUESTS
mysql_select_db($database_CONNECT, $CONNECT);
$query_BrettView = "SELECT * FROM sr WHERE owner = 'Brett'";
$BrettView = mysql_query($query_BrettView, $CONNECT) or die(mysql_error());
$row_BrettView = mysql_fetch_assoc($BrettView);
$totalRows_BrettView = mysql_num_rows($BrettView);

//PULLS ONLY BRUCE'S SERVICE REQUESTS
mysql_select_db($database_CONNECT, $CONNECT);
$query_BruceView = "SELECT * FROM sr WHERE owner = 'Bruce'";
$BruceView = mysql_query($query_BruceView, $CONNECT) or die(mysql_error());
$row_BruceView = mysql_fetch_assoc($BruceView);
$totalRows_BruceView = mysql_num_rows($BruceView);

//PULLS ONLY GARY'S SERVICE REQUESTS
mysql_select_db($database_CONNECT, $CONNECT);
$query_GaryView = "SELECT * FROM sr WHERE owner = 'Gary'";
$GaryView = mysql_query($query_GaryView, $CONNECT) or die(mysql_error());
$row_GaryView = mysql_fetch_assoc($GaryView);
$totalRows_GaryView = mysql_num_rows($GaryView);

//PULLS ONLY VICTOR'S SERVICE REQUESTS
mysql_select_db($database_CONNECT, $CONNECT);
$query_VictorView = "SELECT * FROM sr WHERE owner = 'Victor'";
$VictorView = mysql_query($query_VictorView, $CONNECT) or die(mysql_error());
$row_VictorView = mysql_fetch_assoc($VictorView);
$totalRows_VictorView = mysql_num_rows($VictorView);

mysql_select_db($database_CONNECT, $CONNECT);
$query_Update = "SELECT * FROM sr";
$Update = mysql_query($query_Update, $CONNECT) or die(mysql_error());
$row_Update = mysql_fetch_assoc($Update);
$totalRows_Update = mysql_num_rows($Update);
?><!-- BEGIN HTML PORTION -->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<style type="text/css">
<!--
body {
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
}
.style1 {color: #666666}
.style9 {font-family: Geneva, Arial, Helvetica, sans-serif; font-size: 12px; }
.style10 {font-size: 12px}
.style12 {font-family: Geneva, Arial, Helvetica, sans-serif; font-size: 12px; font-weight: bold; color: #FF0000; }
-->
</style></head>

brettpower
01-31-2007, 08:21 PM
Here is the last part of the code..


<body>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="44%" background="../img/top_repeat.gif"><img src="../img/top_logo.png" width="466" height="98" /></td>
<td width="56%" background="../img/top_repeat.gif">&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
</table>
<table width="100%" border="0" cellpadding="5" cellspacing="0">
<tr>
<td><div align="center" class="style12"><?php echo $totalRows_TriageView ?></div></td>
<td><div align="center" class="style12"><?php echo $totalRows_BrettView ?></div></td>
<td><div align="center" class="style12"><?php echo $totalRows_BruceView ?></div></td>
<td><div align="center" class="style12"><?php echo $totalRows_GaryView ?></div></td>
<td><div align="center" class="style12"><?php echo $totalRows_VictorView ?></div></td>
</tr>
<tr>
<td width="20%"><div align="center"><a href="index.php?tech=UNASSIGNED"><img src="../img/triage.png" alt="f" width="150" height="25" border="0" /></a></div></td>
<td width="20%"><div align="center"><a href="index.php?tech=Brett"><img src="../img/brett.png" alt="f" width="150" height="25" border="0" /></a></div></td>
<td width="20%"><div align="center"><a href="index.php?tech=Bruce"><img src="../img/bruce.png" alt="f" width="150" height="25" border="0" /></a></div></td>
<td width="20%"><div align="center"><a href="index.php?tech=Gary"><img src="../img/gary.png" alt="f" width="150" height="25" border="0" /></a></div></td>
<td width="20%"><div align="center"><a href="index.php?tech=Victor"><img src="../img/victor.png" alt="f" width="150" height="25" border="0" /></a></div></td>
</tr>
</table>
<?php do { ?>
<form method="post" name="form1" action="<?php echo $editFormAction; ?>">
<table width="600" align="center" cellspacing="0" bgcolor="#EEEEEE">
<tr valign="baseline">
<td width="72" align="right" nowrap bgcolor="#CCCCCC"><span class="style9">Issue ID :</span></td>
<td bgcolor="#CCCCCC"><span class="style9"><?php echo $row_UpdateView['id']; ?> / <?php echo $row_UpdateView['owner']; ?></span></td>
<td bgcolor="#CCCCCC"><div align="center" class="style9"><?php echo $row_UpdateView['time']; ?></div></td>
</tr>
<tr valign="baseline">
<td align="right" nowrap bgcolor="#EEEEEE"><span class="style9">Name:</span></td>
<td width="284" bgcolor="#EEEEEE"><span class="style9"><?php echo $row_UpdateView['name']; ?></span></td>
<td width="320" rowspan="7" bgcolor="#EEEEEE"><span class="style9">ISSUE NOTES:
<textarea name="notes" cols="35" rows="12" id="notes"><?php echo $row_UpdateView['notes']; ?></textarea>
</span></td>
</tr>
<tr valign="baseline">
<td align="right" nowrap bgcolor="#EEEEEE"><span class="style9">Phone:</span></td>
<td bgcolor="#EEEEEE"><span class="style9"><?php echo $row_UpdateView['phone']; ?></span></td>
</tr>
<tr valign="baseline">
<td align="right" nowrap bgcolor="#EEEEEE"><span class="style9">Email:</span></td>
<td bgcolor="#EEEEEE"><span class="style9"><?php echo $row_UpdateView['email']; ?></span></td>
</tr>
<tr valign="baseline">
<td align="right" nowrap bgcolor="#EEEEEE"><span class="style9">Location:</span></td>
<td bgcolor="#EEEEEE"><span class="style9"><?php echo $row_UpdateView['location']; ?></span></td>
</tr>
<tr valign="baseline">
<td colspan="2" align="right" valign="top" nowrap bgcolor="#EEEEEE"><span class="style10"><span class="style9">
<input name="id" type="hidden" id="id" value="<?php echo $row_UpdateView['id']; ?>"/>
<input name="time" type="hidden" id="time" value="<?php echo $row_UpdateView['time']; ?>"/>
<input name="email" type="hidden" id="email" value="<?php echo $row_UpdateView['email']; ?>"/>
<input name="phone" type="hidden" id="phone" value="<?php echo $row_UpdateView['phone']; ?>"/>
<input name="name" type="hidden" id="name" value="<?php echo $row_UpdateView['name']; ?>"/>
<input name="location" type="hidden" id="location" value="<?php echo $row_UpdateView['location']; ?>"/>
</span></span></td>
</tr>
<tr valign="baseline">
<td align="right" nowrap bgcolor="#EEEEEE"><span class="style9">Status:</span></td>
<td bgcolor="#EEEEEE"><span class="style9">
<input type="text" name="status" value="<?php echo $row_UpdateView['status']; ?>" size="10" />
</span></td>
</tr>
<tr valign="baseline">
<td colspan="2" align="right" nowrap bgcolor="#EEEEEE"><span class="style9"> </span><span class="style9">
<label> </label>
</span>
<label>
<div align="left"> <span class="style9">
<textarea name="description" cols="40" rows="5"><?php echo $row_UpdateView['description']; ?></textarea>
</span>
<div align="center"></div>
</div>
</label>
<span class="style9"></span><span class="style9"> </span></td>
</tr>
<tr valign="baseline">
<td align="right" nowrap bgcolor="#EEEEEE"><span class="style10"></span></td>
<td colspan="2" bgcolor="#EEEEEE"><input type="submit" value="Update Issue"></td>
</tr>
<tr valign="baseline">
<td colspan="3" align="right" nowrap><span class="style1"></span>
<hr />
<span class="style1"></span></td>
</tr>
<tr valign="baseline">
<td colspan="3" align="right" nowrap bgcolor="#FFFFFF">&nbsp;</td>
</tr>
</table>
<br />
<input type="hidden" name="MM_update" value="form1">
</form>
<?php } while ($row_UpdateView = mysql_fetch_assoc($UpdateView)); ?>
</body>
</html>
<?php
mysql_free_result($UpdateView);

//mysql_free_result($Users);

//mysql_free_result($Status);

mysql_free_result($TriageView);

mysql_free_result($BrettView);

mysql_free_result($BruceView);

mysql_free_result($GaryView);

mysql_free_result($VictorView);

mysql_free_result($Update);
?>

davidj
01-31-2007, 08:23 PM
ya daft monkey

you still have the echo that we used to echo the update statement when we debuged it

brettpower
01-31-2007, 08:25 PM
lol. I did have it out, but then put it back in because the problem still existed without it....I wanted to see what was going wrong.

davidj
01-31-2007, 08:29 PM
is it still broken?

brettpower
01-31-2007, 08:32 PM
Sorry for the non-specific post there. What is still broken is the database not being updated. The header error is gone.

davidj
01-31-2007, 08:50 PM
yes i understand now....

you have this..


if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) {


its looking for a form field called MM_update and the value == form1

if this statement is true then it updates but what if you have more than one field called MM_update and more than one value == form1 like if you loop through a form collection

solution follows........

brettpower
01-31-2007, 08:52 PM
that part of the code is Dreamweaver-generated. I will go and take a look...

brettpower
01-31-2007, 09:03 PM
David,
Out network just took a nose-dive here at work....I will be back as soon as I can. thanks for helping my out today....I really appreciate it.

brettpower
01-31-2007, 09:18 PM
Alright, I'm Back now...

davidj
01-31-2007, 09:52 PM
i need to simulate your model

this may take a few minutes

brettpower
01-31-2007, 09:59 PM
I think I am in the 65% right now! lol

brettpower
01-31-2007, 10:19 PM
Removing the single quotes did the trick. It is amazing that I passed over that so many times without seeing it. Thanks a bunch, david.

davidj
01-31-2007, 10:21 PM
i deleted that post by mistake

hehe

brettpower
01-31-2007, 10:22 PM
The sick thing is is that I added those quotes a long time ago while trying to narrow some possibilities, but, as you can see, I forgot to take them back out. We've all done it.....!

davidj
01-31-2007, 10:24 PM
please take some time to follow my video tutorials

http://www.dreamweaverclub.com/vtm/

This is a good primer for getting into hand coding

an couple of hours to follow them all is all you need and you will never allow dreamweaver anywhere near your code again