edvinson
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!
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!
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.
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
ASKER
OK here goes.
<?php require_once('../Connectio ns/PlugASo ng.php'); ?>
<?php
if (!function_exists("GetSQLV alueString ")) {
function GetSQLValueString($theValu e, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
$theValue = function_exists("mysql_rea l_escape_s tring") ? mysql_real_escape_string($ theValue) : mysql_escape_string($theVa lue);
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_STR ING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUE RY_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_STR ING'])) {
$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 _Recordset 1, "int"));
$Recordset1 = mysql_query($query_Records et1, $PlugASong) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Records et1);
$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($Records et1);
mysql_free_result($Records et1);
?>
<?php require_once('../Connectio
<?php
if (!function_exists("GetSQLV
function GetSQLValueString($theValu
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
$theValue = function_exists("mysql_rea
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_STR
$editFormAction .= "?" . htmlentities($_SERVER['QUE
}
if ((isset($_POST["MM_update"
$updateSQL = sprintf("UPDATE users SET zip=%s, `state`=%s, city=%s, address=%s, username=%s, password=%s WHERE ID=%s",
GetSQLValueString($_POST['
GetSQLValueString($_POST['
GetSQLValueString($_POST['
GetSQLValueString($_POST['
GetSQLValueString($_POST['
GetSQLValueString($_POST['
GetSQLValueString($_POST['
mysql_select_db($database_
$Result1 = mysql_query($updateSQL, $PlugASong) or die(mysql_error());
$updateGoTo = "updated.php";
if (isset($_SERVER['QUERY_STR
$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_
$query_Recordset1 = sprintf("SELECT * FROM users WHERE ID = %s", GetSQLValueString($colname
$Recordset1 = mysql_query($query_Records
$row_Recordset1 = mysql_fetch_assoc($Records
$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($Records
mysql_free_result($Records
?>
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.
$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.
ASKER
Jason, it appears to me that is what I've done in the requestor box: See screenshot: Not much luck yet.
screenshot.jpg
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 ']);
}
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
}
ASKER
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('../Connectio ns/PlugASo ng.php'); ?>
<?php
if (!function_exists("GetSQLV alueString ")) {
function GetSQLValueString($theValu e, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
$theValue = function_exists("mysql_rea l_escape_s tring") ? mysql_real_escape_string($ theValue) : mysql_escape_string($theVa lue);
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("GetSQLV alueString ")) {
function GetSQLValueString($theValu e, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
$theValue = function_exists("mysql_rea l_escape_s tring") ? mysql_real_escape_string($ theValue) : mysql_escape_string($theVa lue);
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_STR ING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUE RY_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_STR ING'])) {
$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 _Recordset 1, "int"));
$Recordset1 = mysql_query($query_Records et1, $PlugASong) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Records et1);
$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($Records et1);
mysql_free_result($Records et1);
mysql_free_result($Records et1);
?>
Aparently there is something else wrong, somewhere else, possible on the the detail.php page?
Source code now for detail2.php:
<?php require_once('../Connectio
<?php
if (!function_exists("GetSQLV
function GetSQLValueString($theValu
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
$theValue = function_exists("mysql_rea
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("GetSQLV
function GetSQLValueString($theValu
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
$theValue = function_exists("mysql_rea
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_STR
$editFormAction .= "?" . htmlentities($_SERVER['QUE
}
if ((isset($_POST["MM_update"
$updateSQL = sprintf("UPDATE users SET zip=%s, `state`=%s, city=%s, address=%s, username=%s, password=%s WHERE ID=%s",
GetSQLValueString($_POST['
GetSQLValueString($_POST['
GetSQLValueString($_POST['
GetSQLValueString($_POST['
GetSQLValueString($_POST['
GetSQLValueString($_POST['
GetSQLValueString($_POST['
mysql_select_db($database_
$Result1 = mysql_query($updateSQL, $PlugASong) or die(mysql_error());
$updateGoTo = "updated.php";
if (isset($_SERVER['QUERY_STR
$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_
$query_Recordset1 = sprintf("SELECT * FROM users WHERE ID = %s ORDER BY ID ASC", GetSQLValueString($colname
$Recordset1 = mysql_query($query_Records
$row_Recordset1 = mysql_fetch_assoc($Records
$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($Records
mysql_free_result($Records
mysql_free_result($Records
?>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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!
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!
ASKER
Jason is awesome and was patient with my amateur self! Thanks again,
e!
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.
>> 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.
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.