| Mibble 2004-08-13, 11:15 pm |
| Hello,
I have attached the code which is generated by Dreamweaver, for inserting a
record from the wizard. That part works great. I also added a small section
below the insert record so after insertion, I go back to where I can insert
again, and the new record is displayed.
What I would like to know, is how I can add a hyperlink to the 'model' to make
it selectable, where I can update the record by editing it, or delete the
record by selecting it, while keeping the insert record (Add Model) to the form.
Thanks!
<?php require_once('Connections/ucl.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_insert"])) && ($_POST["MM_insert"] == "addmodel")) {
$insertSQL = sprintf("INSERT INTO model (model_id, model) VALUES (%s, %s)",
GetSQLValueString($_POST['model_id'], "int"),
GetSQLValueString($_POST['model'], "text"));
mysql_select_db($database_ucl, $ucl);
$Result1 = mysql_query($insertSQL, $ucl) or die(mysql_error());
$insertGoTo = "add_model.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
mysql_select_db($database_ucl, $ucl);
$query_Add_Model = "SELECT * FROM model ORDER BY model ASC";
$Add_Model = mysql_query($query_Add_Model, $ucl) or die(mysql_error());
$row_Add_Model = mysql_fetch_assoc($Add_Model);
$totalRows_Add_Model = mysql_num_rows($Add_Model);
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Add Model</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<div align="center">
<h2><strong>Add Model</strong></h2>
</div>
<div align="center">
<form method="post" name="addmodel" action="<?php echo $editFormAction; ?>">
<table align="center">
<tr valign="baseline">
<td nowrap align="right">Model:</td>
<td><input type="text" name="model" value="" size="20"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right"> </td>
<td><input type="submit" value="Add Model"></td>
</tr>
</table>
<input type="hidden" name="model_id" value="">
<input type="hidden" name="MM_insert" value="addmodel">
</form>
<table border="1" cellspacing="0" cellpadding="7">
<tr>
<th scope="col">Model ID </th>
<th scope="col">Model</th>
</tr>
<?php do { ?>
<tr>
<td><?php echo $row_Add_Model['model_id']; ?></td>
<td><?php echo $row_Add_Model['model']; ?></td>
</tr>
<?php } while ($row_Add_Model = mysql_fetch_assoc($Add_Model)); ?>
</table>
</div>
</body>
</html>
<?php
mysql_free_result($Add_Model);
?>
|