Solved

Dreamweaver Update Record PHP not working

Posted on 2010-11-13
14
351 Views
Last Modified: 2012-05-10
Seems this is hit and miss.  I manually made a form and tied the ID from the previous page (in a recordset dynamic table).  When the user clicks on the ID it is a link to the update_record.php page.  Everything seems fine but the record is not updating for some reason.  No error codes or anything displays, just the form does not work.  The form has dynamic form fields on it so the user can update and see what is currently in the DB.  I'm not much of a coder so don't know if I'm missing something in my code but it even goes to the update_success.php page after updating, but nothing has changed in the DB.  Any ideas?
0
Comment
Question by:palmtreeinfotech
  • 8
  • 6
14 Comments
 

Author Comment

by:palmtreeinfotech
ID: 34129799

<?php require_once('../Connections/connect01.php'); ?>

<?php

if (!function_exists("GetSQLValueString")) {

function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 

{

  if (PHP_VERSION < 6) {

    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

  }



  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($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 tblInfo SET Modified=%s, Bus_Name=%s, Contact_Name=%s, Address=%s, City=%s, `State`=%s, Zip=%s, Phone=%s, Fax=%s, Email=%s, Website=%s, Active=%s, Bus_Month=%s, Bus_Year=%s, Comments=%s WHERE ID=%s",

                       GetSQLValueString($_POST['datemodified'], "date"),

                       GetSQLValueString($_POST['busname'], "text"),

                       GetSQLValueString($_POST['contactname'], "text"),

                       GetSQLValueString($_POST['address'], "text"),

                       GetSQLValueString($_POST['city'], "text"),

                       GetSQLValueString($_POST['state'], "text"),

                       GetSQLValueString($_POST['zip'], "text"),

                       GetSQLValueString($_POST['phone'], "text"),

                       GetSQLValueString($_POST['fax'], "text"),

                       GetSQLValueString($_POST['email'], "text"),

                       GetSQLValueString($_POST['website'], "text"),

                       GetSQLValueString($_POST['status'], "int"),

                       GetSQLValueString($_POST['bommonth'], "text"),

                       GetSQLValueString($_POST['bomyear'], "text"),

                       GetSQLValueString($_POST['comments'], "text"),

                       GetSQLValueString($_POST['id'], "int"));



  mysql_select_db($database_connect01, $connect01);

  $Result1 = mysql_query($updateSQL, $connect01) or die(mysql_error());



  $updateGoTo = "update_success.php";

  if (isset($_SERVER['QUERY_STRING'])) {

    $updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";

    $updateGoTo .= $_SERVER['QUERY_STRING'];

  }

  header(sprintf("Location: %s", $updateGoTo));

}



$colname_Recordset1 = "-1";

if (isset($_GET['ID'])) {

  $colname_Recordset1 = $_GET['ID'];

}

mysql_select_db($database_connect01, $connect01);

$query_Recordset1 = sprintf("SELECT * FROM tblInfo WHERE ID = %s", GetSQLValueString($colname_Recordset1, "int"));

$Recordset1 = mysql_query($query_Recordset1, $connect01) or die(mysql_error());

$row_Recordset1 = mysql_fetch_assoc($Recordset1);

$totalRows_Recordset1 = mysql_num_rows($Recordset1);

?>

<!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=utf-8" />

<title>Admin Login for Members PACC Site</title>

<style type="text/css">

body {

	background-image: url(images/bluestrip_bg.png);

}

</style>

</head>



<body>

<p>You are updating this business.  The database will not update until you have &quot;submitted&quot; your changes below.</p>

<p>You will receive a confirmation page once updated correctly.</p>

<form action="<?php echo $editFormAction; ?>" id="form1" name="form1" method="POST">

  <table width="100%" border="1" cellpadding="2" cellspacing="2">

    <tr>

      <td width="22%">ID:</td>

      <td width="78%"><label for="id"></label>

      <input name="id" type="text" disabled="disabled" id="id" value="<?php echo $row_Recordset1['ID']; ?>" /></td>

    </tr>

    <tr>

      <td>Date Added:</td>

      <td><label for="dateadded"></label>

      <input name="dateadded" type="text" disabled="disabled" id="dateadded" value="<?php echo $row_Recordset1['Date_Added']; ?>" size="45" /></td>

    </tr>

    <tr>

      <td>Date Last Modified:</td>

      <td><label for="datemodified"></label>

      <input name="datemodified" type="text" disabled="disabled" id="datemodified" value="<?php date("F j, Y, g:i a")?>" size="45" /></td>

    </tr>

    <tr>

      <td>Business Name:</td>

      <td><label for="busname"></label>

      <input value="<?php echo $row_Recordset1['Bus_Name']; ?>" name="busname" type="text" id="busname" size="45" /></td>

    </tr>

    <tr>

      <td>Contact Name:</td>

      <td><input value="<?php echo $row_Recordset1['Contact_Name']; ?>" name="contactname" type="text" id="contactname" size="45" /></td>

    </tr>

    <tr>

      <td>Address:</td>

      <td><input value="<?php echo $row_Recordset1['Address']; ?>" name="address" type="text" id="address" size="45" /></td>

    </tr>

    <tr>

      <td>City:</td>

      <td><input value="<?php echo $row_Recordset1['City']; ?>" name="city" type="text" id="city" size="45" /></td>

    </tr>

    <tr>

      <td>State:</td>

      <td><input value="<?php echo $row_Recordset1['State']; ?>" name="state" type="text" id="state" size="10" /></td>

    </tr>

    <tr>

      <td>Zip:</td>

      <td><input value="<?php echo $row_Recordset1['Zip']; ?>" name="zip" type="text" id="zip" size="15" /></td>

    </tr>

    <tr>

      <td>Phone:</td>

      <td><input value="<?php echo $row_Recordset1['Phone']; ?>" name="phone" type="text" id="phone" size="45" /></td>

    </tr>

    <tr>

      <td>Fax:</td>

      <td><input value="<?php echo $row_Recordset1['Fax']; ?>" name="fax" type="text" id="fax" size="45" /></td>

    </tr>

    <tr>

      <td>Email Address:</td>

      <td><input value="<?php echo $row_Recordset1['Email']; ?>" name="email" type="text" id="email" size="45" /></td>

    </tr>

    <tr>

      <td>Website:</td>

      <td><input value="<?php echo $row_Recordset1['Website']; ?>" name="website" type="text" id="website" size="45" /></td>

    </tr>

    <tr>

      <td>Active?</td>

      <td><label for="status"></label>

        <select name="status" id="status">

          <option value="1" <?php if (!(strcmp(1, $row_Recordset1['Active']))) {echo "selected=\"selected\"";} ?>>Active</option>

          <option value="2" <?php if (!(strcmp(2, $row_Recordset1['Active']))) {echo "selected=\"selected\"";} ?>>Inactive</option>

      </select></td>

    </tr>

    <tr>

      <td>Business of the Month Month:</td>

      <td><label for="bommonth"></label>

        <select name="bommonth" id="bommonth">

          <option value="01" <?php if (!(strcmp(01, $row_Recordset1['Bus_Month']))) {echo "selected=\"selected\"";} ?>>January</option>

          <option value="02" <?php if (!(strcmp(02, $row_Recordset1['Bus_Month']))) {echo "selected=\"selected\"";} ?>>February</option>

          <option value="03" <?php if (!(strcmp(03, $row_Recordset1['Bus_Month']))) {echo "selected=\"selected\"";} ?>>March</option>

          <option value="04" <?php if (!(strcmp(04, $row_Recordset1['Bus_Month']))) {echo "selected=\"selected\"";} ?>>April</option>

          <option value="05" <?php if (!(strcmp(05, $row_Recordset1['Bus_Month']))) {echo "selected=\"selected\"";} ?>>May</option>

          <option value="06" <?php if (!(strcmp(06, $row_Recordset1['Bus_Month']))) {echo "selected=\"selected\"";} ?>>June</option>

          <option value="07" <?php if (!(strcmp(07, $row_Recordset1['Bus_Month']))) {echo "selected=\"selected\"";} ?>>July</option>

          <option value="08" <?php if (!(strcmp(08, $row_Recordset1['Bus_Month']))) {echo "selected=\"selected\"";} ?>>August</option>

          <option value="09" <?php if (!(strcmp(09, $row_Recordset1['Bus_Month']))) {echo "selected=\"selected\"";} ?>>September</option>

          <option value="10" <?php if (!(strcmp(10, $row_Recordset1['Bus_Month']))) {echo "selected=\"selected\"";} ?>>October</option>

          <option value="11" <?php if (!(strcmp(11, $row_Recordset1['Bus_Month']))) {echo "selected=\"selected\"";} ?>>November</option>

          <option value="12" <?php if (!(strcmp(12, $row_Recordset1['Bus_Month']))) {echo "selected=\"selected\"";} ?>>December</option>

          <option value="" <?php if (!(strcmp("", $row_Recordset1['Bus_Month']))) {echo "selected=\"selected\"";} ?>>Not selected...</option>

        </select></td>

    </tr>

    <tr>

      <td>Business of the Month Year:</td>

      <td><label for="bomyear"></label>

        <select name="bomyear" id="bomyear">

          <option value="2010" <?php if (!(strcmp(2010, $row_Recordset1['Bus_Year']))) {echo "selected=\"selected\"";} ?>>2010</option>

          <option value="2011" <?php if (!(strcmp(2011, $row_Recordset1['Bus_Year']))) {echo "selected=\"selected\"";} ?>>2011</option>

          <option value="2012" <?php if (!(strcmp(2012, $row_Recordset1['Bus_Year']))) {echo "selected=\"selected\"";} ?>>2012</option>

          <option value="" <?php if (!(strcmp("", $row_Recordset1['Bus_Year']))) {echo "selected=\"selected\"";} ?>>Not selected...</option>

        </select></td>

    </tr>

    <tr>

      <td>Comments:</td>

      <td><label for="comments"></label>

      <textarea name="comments" id="comments" cols="70" rows="10"><?php echo $row_Recordset1['Comments']; ?></textarea></td>

    </tr>

    <tr>

      <td>&nbsp;</td>

      <td><input type="submit" name="button" id="button" value="Submit" /></td>

    </tr>

  </table>

  <input type="hidden" name="MM_update" value="form1" />

</form>

<p>&nbsp;</p>

<p>&nbsp;</p>

</body>

</html>

<?php

mysql_free_result($Recordset1);

?>

Open in new window

0
 

Author Comment

by:palmtreeinfotech
ID: 34129825
As a side note, I'm trying to update the [modified] field in the DB when the user hits the submit button.  I have it has a hidden field called "modified" which is the same field as my database and I have the value set at <?php date("y:m:d h:i:s")?>

Would this update in the database based on the time they hit the submit button to the [modified] field each time?  Or should I be posting another question for this?
0
 
LVL 70

Expert Comment

by:Jason C. Levine
ID: 34129833
Hi again, palmtreeinfotech,

Your recordset is looking for a URL parameter named ID:

$colname_Recordset1 = "-1";
if (isset($_GET['ID'])) {
  $colname_Recordset1 = $_GET['ID'];
}


Is the URL something.php?ID=xxx or something.php?id=xxx

Because if it is the latter, this won't work as PHP is case sensitive.

>> Would this update in the database based on the time they hit the submit button to the [modified]
>> field each time?

Yes, but easier to set the field to a TIMESTAMP and then set it to ON UPDATE CURRENT TIMESTAMP.  So each time the row is updated, it gets the latest system time and date.  
0
 

Author Comment

by:palmtreeinfotech
ID: 34129850
Hi Jason!  You're the resident expert I see!

I changed my text field name to capital "ID" and that didn't make a difference.  It's actually linking correctly from the previous page based on the ID of the row in the table:

update_record.php?ID=1

The actual URL Param id is "ID" on both page.

What I did on the timestamp is tell Dreamweaver to update my hidden field (hiddenmodified) to update to my database field of [modified] and set the hidden field to "now()" but not sure that will work in MySQL though.

Everything seems to be working except the update is still not working??
0
 
LVL 70

Expert Comment

by:Jason C. Levine
ID: 34129857
>> Hi Jason!  You're the resident expert I see!

For Dreamweaver, more or less.  I also tend to be home at nights because having a small child really ruins ones ability to be out on Saturday nights :)

1. When you go to the update page, are the form fields prepopulated?  That will handle the passing of the $_GET array

2. If the form fields are prepopulated, the error is most likely here:

<input name="id" type="text" disabled="disabled" id="id" value="<?php echo $row_Recordset1['ID']; ?>" />

disabled="disabled" may prevent the form from submitting the data altogether.  Better to do:

<input name="id" type="hidden" id="id" value="<?php echo $row_Recordset1['ID']; ?>" />

or, if it must be visible:

<input name="id" type="text" readdonly id="id" value="<?php echo $row_Recordset1['ID']; ?>" />

0
 
LVL 70

Expert Comment

by:Jason C. Levine
ID: 34129861
I don't think setting to NOW() will work as expected.  You really should define it like so:

ALTER TABLE `tblInfo` CHANGE `datemodified` `datemodified` TIMESTAMP( 23 ) ON UPDATE CURRENT_TIMESTAMP NOT NULL
0
 

Author Comment

by:palmtreeinfotech
ID: 34129874
Hey Jason cool I understand!  I took off the "disabled" and to no avail no change.

I'm not much of a coder.  In any case, I changed my hiddenfield of [modified] to timestamp().  I will see if that works but I won't know until I can get the page to actually update!

Good suggestions.  Anymore ideas?  Everything seems to be working great but just no updates to the database.  Weird.
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 70

Expert Comment

by:Jason C. Levine
ID: 34129879
Can I get a link to the page for testing?
0
 

Author Comment

by:palmtreeinfotech
ID: 34129884
Sure!

http://peculiarchamber.com/admin2341231/index.php
Login:  admin
Pass:  MDDBel9jpU

It's okay to post on here..I just have the session variable set so you cannot access the page without logging in first.  I'm just testing anyway.

After login, mainmenu.php, click on an ID, takes you to update page. Change something then hit Submit, go back to main menu and record not updated!  Frustrating.  Thank you so much for looking at it!
0
 
LVL 70

Accepted Solution

by:
Jason C. Levine earned 500 total points
ID: 34129889
Can you post the current source code of update_record.php too?  I see a discrepancy and I think you misunderstood my first post.

Your current HTML has:

<input type="text" value="1" id="ID" disabled="disabled" name="ID" gtbfieldid="70">

But the PHP for the update is looking for:

GetSQLValueString($_POST['id'], "int"));

If the HTML name of the form field is ID then the PHP should be:

GetSQLValueString($_POST['ID'], "int"));
0
 

Author Comment

by:palmtreeinfotech
ID: 34132458
Jason, thank you so much and sorry for the late reply.  I changed the variable like in your example and it still didn't update. :(  I'm wondering if I should delete the update record behaviour and start all over just to be safe?  But I shouldn't have to do that I wouldn't think.  I checked all the other case id=ID and all of them are capitalized in the update query.
0
 

Author Comment

by:palmtreeinfotech
ID: 34132969
Jason, I was playing around and I took off the "disabled" after changing the case id to ID and it seems to be working!  How weird is that?  It should work either way in my opinion...thanks for all your help!
0
 

Author Closing Comment

by:palmtreeinfotech
ID: 34132973
Took off the "disabled" tags and it seems to be working.  Thanks a lot for your help and I hope you and the baby are doing well!
0
 
LVL 70

Expert Comment

by:Jason C. Levine
ID: 34133338
>> I took off the "disabled" after changing the case id to ID and it seems to be working!  How weird is that?

Why would you think it's weird?  Both things were wrong :)

It appears you changed the HTML field name to ID when my first post talked about checking the URL (which turns out to have been a bit of a red herring).  The disabled can prevent the form from submitting the data but this appears to be a browser to browser thing.

>> I hope you and the baby are doing well!

Not a baby.  4.5...he just craps out at an early hour :)
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

I still run into .cgi files every now and then. In some instances, I actually prefer the simplicity of a .cgi script to other options. Since I use DreamWeaver extensively, what I needed was a way to open .cgi scripts in Dreamweaver. And I wanted to …
Adobe Dreamweaver CS5 is a WYSIWYG web page editor that has advanced HTML, CSS, and Javascript rendering functionality and is probably the most well-known HTML editor available. Much of Dreamweaver's appeal centers around the Design View interfac…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now