Link to home
Start Free TrialLog in
Avatar of edvinson
edvinsonFlag for United States of America

asked on

Dreamweaver Design Problem with setting up detail, update record page. Yes, a beginner PHP!

I need to set up a simple admin. Seeing my data, sending to a detail page, make changes and submit to DB. I have the DB setup, and the pages talk to it just fine so I'm at least ready for some real assistance here.
As you can see, at www.plugasong.com/admin/detail.php I got the data to appear with a link from the username. To the next page, how do I get the selection to show up in the form. I created hidden fields for the fields I didn't want to show, but nothing appears.
I can provide login info if you'd like.
I know this is cake to most of you, and hopefully will be to me when you get me though it. Thanks
e!
Avatar of Jason C. Levine
Jason C. Levine
Flag of United States of America image

Hi edvinson,

On the detail page, you need to create a recordset that filters on the URL Parameter passed to it by the master page.

So from this link:

http://www.plugasong.com/admin/detail2.php?recordID=6

you tell DW to filter on column recordID (or whatever it is called) using url parameter recordID

Once that is set up, you can then assign the data to the form fields by clicking the little lightning bolt next to the value box in the Properties panel.
Avatar of edvinson

ASKER

Sage , thanks for getting back to me. I did all the above. Didn't seem to work as you'll see:

www.plugasong.com/admin/detail.php

I did assign the data fields to the form but nothing appears. hmmm

want to look inside? I've set up a temporary password.
No need for that.  Just post the source code of detail2.php
OK here goes.


<?php require_once('../Connections/PlugASong.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
  $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 users SET zip=%s, `state`=%s, city=%s, address=%s, username=%s, password=%s WHERE ID=%s",
                       GetSQLValueString($_POST['zip'], "text"),
                       GetSQLValueString($_POST['state'], "text"),
                       GetSQLValueString($_POST['city'], "text"),
                       GetSQLValueString($_POST['address'], "text"),
                       GetSQLValueString($_POST['username'], "text"),
                       GetSQLValueString($_POST['password'], "text"),
                       GetSQLValueString($_POST['ID'], "int"));

  mysql_select_db($database_PlugASong, $PlugASong);
  $Result1 = mysql_query($updateSQL, $PlugASong) or die(mysql_error());

  $updateGoTo = "updated.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_magic_quotes_gpc()) ? $_GET['ID'] : addslashes($_GET['ID']);
}
mysql_select_db($database_PlugASong, $PlugASong);
$query_Recordset1 = sprintf("SELECT * FROM users WHERE ID = %s", GetSQLValueString($colname_Recordset1, "int"));
$Recordset1 = mysql_query($query_Recordset1, $PlugASong) 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=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>
<form action="<?php echo $editFormAction; ?>" id="form1" name="form1" method="POST">
  <div align="center">
    <p>
      <input name="username" type="text" id="username" value="<?php echo $row_Recordset1['username']; ?>" />
    </p>
    <p>
      <input name="password" type="text" id="password" value="<?php echo $row_Recordset1['password']; ?>" />
    </p>
    <p>
      <input name="city" type="text" id="city" value="<?php echo $row_Recordset1['city']; ?>" />
                                                                          
</p>
    <p>
      <input type="submit" name="Submit" value="Submit" />
      <input name="state" type="hidden" id="state" value="<?php echo $row_Recordset1['state']; ?>" />
      <input name="address" type="hidden" id="address" value="<?php echo $row_Recordset1['address']; ?>" />
      <input name="ID" type="hidden" id="ID" value="<?php echo $row_Recordset1['ID']; ?>" />
      <input name="zip" type="hidden" id="zip" value="<?php echo $row_Recordset1['zip']; ?>" />
    </p>
  </div>
 
 
 
  <input type="hidden" name="MM_update" value="form1">
</form>
</body>
</html>
<?php
mysql_free_result($Recordset1);

mysql_free_result($Recordset1);
?>
This part is wrong:

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

ID is the name of the column.  The URL parameter is recordID.

So set the recordset to use ID as the column to filter on and recordID as the URL parameter.
Jason, it appears to me that is what I've done in the requestor box: See screenshot: Not much luck yet.
screenshot.jpg
Nope.

Filter: ID = URL Parameter recordID

Not ID = ID

The URL Parameter is whatever appears after the ? in the URL.  This is called the Query String or the $_GET array.

So for http://www.plugasong.com/admin/detail2.php?recordID=6

The query string is recordID=6.  You need to tell DW to use recordID as the URL parameter.  The code it will write will look like this:

$colname_Recordset1 = "-1";
if (isset($_GET['recordID'])) {
  $colname_Recordset1 = (get_magic_quotes_gpc()) ? $_GET['recordID'] : addslashes($_GET['recordID']);
}

Hmmm Jason, I told the selector box to Filter ID, URL parameter and I had to overwrite the word ID with "recordID" in order to get it to take it, but it did.

Aparently there is something else wrong, somewhere else, possible on the the detail.php page?
Source code now for detail2.php:

<?php require_once('../Connections/PlugASong.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
  $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;
}
}

if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
  $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 users SET zip=%s, `state`=%s, city=%s, address=%s, username=%s, password=%s WHERE ID=%s",
                       GetSQLValueString($_POST['zip'], "text"),
                       GetSQLValueString($_POST['state'], "text"),
                       GetSQLValueString($_POST['city'], "text"),
                       GetSQLValueString($_POST['address'], "text"),
                       GetSQLValueString($_POST['username'], "text"),
                       GetSQLValueString($_POST['password'], "text"),
                       GetSQLValueString($_POST['ID'], "int"));

  mysql_select_db($database_PlugASong, $PlugASong);
  $Result1 = mysql_query($updateSQL, $PlugASong) or die(mysql_error());

  $updateGoTo = "updated.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
    $updateGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $updateGoTo));
}

$colname_Recordset1 = "-1";
if (isset($_GET['RecordID'])) {
  $colname_Recordset1 = (get_magic_quotes_gpc()) ? $_GET['RecordID'] : addslashes($_GET['RecordID']);
}
mysql_select_db($database_PlugASong, $PlugASong);
$query_Recordset1 = sprintf("SELECT * FROM users WHERE ID = %s ORDER BY ID ASC", GetSQLValueString($colname_Recordset1, "int"));
$Recordset1 = mysql_query($query_Recordset1, $PlugASong) 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=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>
<form action="<?php echo $editFormAction; ?>" id="form1" name="form1" method="POST">
  <div align="center">
    <p>
      <input name="username" type="text" id="username" value="<?php echo $row_Recordset1['username']; ?>" />
    </p>
    <p>
      <input name="password" type="text" id="password" value="<?php echo $row_Recordset1['password']; ?>" />
    </p>
    <p>
      <input name="city" type="text" id="city" value="<?php echo $row_Recordset1['city']; ?>" />
                                                                          
</p>
    <p>
      <input type="submit" name="Submit" value="Submit" />
      <input name="state" type="hidden" id="state" value="<?php echo $row_Recordset1['state']; ?>" />
      <input name="address" type="hidden" id="address" value="<?php echo $row_Recordset1['address']; ?>" />
      <input name="ID" type="hidden" id="ID" value="<?php echo $row_Recordset1['ID']; ?>" />
      <input name="zip" type="hidden" id="zip" value="<?php echo $row_Recordset1['zip']; ?>" />
    </p>
  </div>
 
 
 
  <input type="hidden" name="MM_update" value="form1">
</form>
</body>
</html>
<?php
mysql_free_result($Recordset1);

mysql_free_result($Recordset1);

mysql_free_result($Recordset1);
?>
ASKER CERTIFIED SOLUTION
Avatar of Jason C. Levine
Jason C. Levine
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
YESSSSSSSSSSSSSSSSSSSSSSSS!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Touchdown!!! Good job Jason. I know it was probably way beneath your interests, capabilities and patience...but you have been a tremendous help!!

Thank you
e!
Jason is awesome and was patient with my amateur self! Thanks again,

e!
>> I know it was probably way beneath your interests, capabilities and patience...but you have been a tremendous
>> help!! Thank you

Nah, not beneath any of those things, not even my dignity: ).  You are also a very minor part of EE history now...this answer pushes me over the 1,000,000 point mark for DW.

w00t!

Good luck and you're welcome.  Feel free to post a new question when you get stuck again.