logo-dw

Go Back   Dreamweaver Club Forums > Hand Coders Forum > General
Register FAQ Members List Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Display Modes
Old 01-31-2007, 03:40 PM   #1
brettpower
 
Join Date: Jan 2007
Posts: 26
Default Problem updating records

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
HTML 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 is offline   Reply With Quote
Old 01-31-2007, 03:41 PM   #2
brettpower
 
Join Date: Jan 2007
Posts: 26
Default

Here is the second part of my code:

HTML 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);
?>
brettpower is offline   Reply With Quote
Old 01-31-2007, 05:35 PM   #3
davidj
davidj's Avatar
 
Join Date: Sep 2005
Location: The Toon (newcastle upon Tyne)
Posts: 8,256
Default

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;

PHP Code:
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
__________________
Would you like to learn PHP from me? Check out -> www.codezenith.co.uk
davidj is offline   Reply With Quote
Old 01-31-2007, 06:23 PM   #4
brettpower
 
Join Date: Jan 2007
Posts: 26
Default

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....
Code:
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
brettpower is offline   Reply With Quote
Old 01-31-2007, 06:34 PM   #5
davidj
davidj's Avatar
 
Join Date: Sep 2005
Location: The Toon (newcastle upon Tyne)
Posts: 8,256
Default

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
__________________
Would you like to learn PHP from me? Check out -> www.codezenith.co.uk
davidj is offline   Reply With Quote
Old 01-31-2007, 06:39 PM   #6
brettpower
 
Join Date: Jan 2007
Posts: 26
Default

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!
brettpower is offline   Reply With Quote
Old 01-31-2007, 06:41 PM   #7
davidj
davidj's Avatar
 
Join Date: Sep 2005
Location: The Toon (newcastle upon Tyne)
Posts: 8,256
Default

view the source of the page when your running it to see if this field is getting populated with the var id...
__________________
Would you like to learn PHP from me? Check out -> www.codezenith.co.uk
davidj is offline   Reply With Quote
Old 01-31-2007, 07:04 PM   #8
brettpower
 
Join Date: Jan 2007
Posts: 26
Default

View source tells me that everything should be just fine. All fields are populated correctly.

Back to the code.....
brettpower is offline   Reply With Quote
Old 01-31-2007, 07:07 PM   #9
brettpower
 
Join Date: Jan 2007
Posts: 26
Default

I am willing to bet the problem is and has been right in front of my face the whole time!
brettpower is offline   Reply With Quote
Old 01-31-2007, 07:18 PM   #10
davidj
davidj's Avatar
 
Join Date: Sep 2005
Location: The Toon (newcastle upon Tyne)
Posts: 8,256
Default

i have just viewed source and all your hidden fields are empty including the ID??
__________________
Would you like to learn PHP from me? Check out -> www.codezenith.co.uk
davidj is offline   Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 04:00 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2018, vBulletin Solutions, Inc.
Copyright 2006 DreamweaverClub.com