livewirewebsolutions
asked on
php and mysql
I am trying to display all the records from a mysql database in a table and have the results all editable. I want to be able to edit the records right in the table. I can display the data but not edit it. How do I do this?
thanx,
Lorne
thanx,
Lorne
ASKER
Once the table is displayed, I can't change any values. They are not editable.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I am using dreamweaver and putting code together from other pages. I am now able to display all the data in a table and edit it. However, when I update the table,after making changes, all the entries in the database are changed to the last entry. So all entries are the same. It is completely screwed up. I'll show you the code here,
<?php require_once('Connections/ connsearch .php'); ?>
<?php
function GetSQLValueString($theValu e, $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_STR ING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUE RY_STRING' ]);
}
if ((isset($_POST["MM_update" ])) && ($_POST["MM_update"] == "form1")) {
$updateSQL = sprintf("UPDATE table1 SET scottid=%s,companyname=%s, addressline1=%s, addressline2=%s, city=%s, province=%s, postalcode=%s, telephone=%s, fax=%s, website=%s, email=%s, subscription=%s WHERE scottid=%s",
GetSQLValueString($_POST[' scottid'], "text"),
GetSQLValueString($_POST[' companynam e'], "text"),
GetSQLValueString($_POST[' addresslin e1'], "text"),
GetSQLValueString($_POST[' addresslin e2'], "text"),
GetSQLValueString($_POST[' city'], "text"),
GetSQLValueString($_POST[' province'] , "text"),
GetSQLValueString($_POST[' postalcode '], "text"),
GetSQLValueString($_POST[' telephone' ], "text"),
GetSQLValueString($_POST[' fax'], "text"),
GetSQLValueString($_POST[' website'], "text"),
GetSQLValueString($_POST[' email'], "text"),
GetSQLValueString($_POST[' subscripti on'], "text"));
mysql_select_db($database_ connsearch , $connsearch);
$Result1 = mysql_query($updateSQL, $connsearch) or die(mysql_error());
$updateGoTo = "confirmation.html";
if (isset($_SERVER['QUERY_STR ING'])) {
$updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
$updateGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $updateGoTo));
}
mysql_select_db($database_ connsearch , $connsearch);
$query_rseditmachines = "SELECT * FROM table1";
$rseditmachines = mysql_query($query_rseditm achines, $connsearch) or die(mysql_error());
$row_rseditmachines = mysql_fetch_assoc($rseditm achines);
$totalRows_rseditmachines = mysql_num_rows($rseditmach ines);
?><!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>editmachines.php</t itle>
</head>
<body>
<form id="form1" name="form1" method="post" action="<?php echo $editFormAction; ?>">
<table border="1">
<tr>
<td><strong>scottid</stron g></td>
<td><strong>companyname</s trong></td >
<td><strong>addressline1</ strong></t d>
<td><strong>addressline2</ strong></t d>
<td><strong>city</strong>< /td>
<td><strong>province</stro ng></td>
<td><strong>postalcode</st rong></td>
<td><strong>telephone</str ong></td>
<td><strong>fax</strong></ td>
<td><strong>website</stron g></td>
<td><strong>email</strong> </td>
<td><strong>subscription</ strong></t d>
</tr>
<?php do { ?>
<tr>
<td><input type="text" name="scottid" value="<?php echo $row_rseditmachines['scott id']; ?>"></td>
<td><input type="text" name="companyname" value="<?php echo $row_rseditmachines['compa nyname']; ?>"></td>
<td><input type="text" name="addressline1" value="<?php echo $row_rseditmachines['addre ssline1']; ?>"></td>
<td><input type="text" name="addressline2" value="<?php echo $row_rseditmachines['addre ssline2']; ?>"></td>
<td><input type="text" name="city" value="<?php echo $row_rseditmachines['city' ]; ?>" size="32"></td>
<td><input type="text" name="province" value="<?php echo $row_rseditmachines['provi nce']; ?>"></td>
<td><input type="text" name="postalcode" value="<?php echo $row_rseditmachines['posta lcode']; ?>"></td>
<td><input type="text" name="telephone" value="<?php echo $row_rseditmachines['telep hone']; ?>"></td>
<td><input type="text" name="fax" value="<?php echo $row_rseditmachines['fax'] ; ?>"></td>
<td><input type="text" name="website" value="<?php echo $row_rseditmachines['websi te']; ?>"></td>
<td><input type="text" name="email" value="<?php echo $row_rseditmachines['email ']; ?>"></td>
<td><input type="text" name="subscription" value="<?php echo $row_rseditmachines['subsc ription']; ?>"></td>
</tr>
<?php } while ($row_rseditmachines = mysql_fetch_assoc($rseditm achines)); ?>
</table>
<input type="hidden" name="MM_update" value="form1">
<input type="submit" value="Update record">
</form>
</body>
</html>
<?php
mysql_free_result($rseditm achines);
?>
It probably looks like a mess as I have heard that dreamweaver gives some awful code sometimes. Suggestions on changes or a complete overhaul would be appreciated
<?php require_once('Connections/
<?php
function GetSQLValueString($theValu
{
$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_STR
$editFormAction .= "?" . htmlentities($_SERVER['QUE
}
if ((isset($_POST["MM_update"
$updateSQL = sprintf("UPDATE table1 SET scottid=%s,companyname=%s,
GetSQLValueString($_POST['
GetSQLValueString($_POST['
GetSQLValueString($_POST['
GetSQLValueString($_POST['
GetSQLValueString($_POST['
GetSQLValueString($_POST['
GetSQLValueString($_POST['
GetSQLValueString($_POST['
GetSQLValueString($_POST['
GetSQLValueString($_POST['
GetSQLValueString($_POST['
GetSQLValueString($_POST['
mysql_select_db($database_
$Result1 = mysql_query($updateSQL, $connsearch) or die(mysql_error());
$updateGoTo = "confirmation.html";
if (isset($_SERVER['QUERY_STR
$updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
$updateGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $updateGoTo));
}
mysql_select_db($database_
$query_rseditmachines = "SELECT * FROM table1";
$rseditmachines = mysql_query($query_rseditm
$row_rseditmachines = mysql_fetch_assoc($rseditm
$totalRows_rseditmachines = mysql_num_rows($rseditmach
?><!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>editmachines.php</t
</head>
<body>
<form id="form1" name="form1" method="post" action="<?php echo $editFormAction; ?>">
<table border="1">
<tr>
<td><strong>scottid</stron
<td><strong>companyname</s
<td><strong>addressline1</
<td><strong>addressline2</
<td><strong>city</strong><
<td><strong>province</stro
<td><strong>postalcode</st
<td><strong>telephone</str
<td><strong>fax</strong></
<td><strong>website</stron
<td><strong>email</strong>
<td><strong>subscription</
</tr>
<?php do { ?>
<tr>
<td><input type="text" name="scottid" value="<?php echo $row_rseditmachines['scott
<td><input type="text" name="companyname" value="<?php echo $row_rseditmachines['compa
<td><input type="text" name="addressline1" value="<?php echo $row_rseditmachines['addre
<td><input type="text" name="addressline2" value="<?php echo $row_rseditmachines['addre
<td><input type="text" name="city" value="<?php echo $row_rseditmachines['city'
<td><input type="text" name="province" value="<?php echo $row_rseditmachines['provi
<td><input type="text" name="postalcode" value="<?php echo $row_rseditmachines['posta
<td><input type="text" name="telephone" value="<?php echo $row_rseditmachines['telep
<td><input type="text" name="fax" value="<?php echo $row_rseditmachines['fax']
<td><input type="text" name="website" value="<?php echo $row_rseditmachines['websi
<td><input type="text" name="email" value="<?php echo $row_rseditmachines['email
<td><input type="text" name="subscription" value="<?php echo $row_rseditmachines['subsc
</tr>
<?php } while ($row_rseditmachines = mysql_fetch_assoc($rseditm
</table>
<input type="hidden" name="MM_update" value="form1">
<input type="submit" value="Update record">
</form>
</body>
</html>
<?php
mysql_free_result($rseditm
?>
It probably looks like a mess as I have heard that dreamweaver gives some awful code sometimes. Suggestions on changes or a complete overhaul would be appreciated
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
<?php
if(isset($_REQUEST['update
{
$sql = "UPDATE mytable ...";
mysql_query($sql) or die(mysql_error());
}
else
{
?>
<FORM METHOD="post" ACTION="<?=$_SERVER['PHP_S
<INPUT ...>
<INPUT TYPE="hidden" NAME="update">
<SUBMIT ...>
</FORM>
<?php
}
?>
---
Harish