need help modifying "stock" php/mysql dreamweaver code
i am using the dreamweaver cs4 "insert into" function to manage multiple forms on a single page. but i am having difficulty editing the code so that it:
- inserts data from the form into the table
- retrieves the id of the newly added row
- echoes a confirmation message on the same page and a link containing the id (as a reference)
here is what dreamweaver has given me so far... it should only add a new row to database (untested):
<?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_insert"])) && ($_POST["MM_insert"] == "form")) {
$insertSQL = sprintf("INSERT INTO tbl_solicitors (solicitorName, solicitorDetail) VALUES (%s, %s)",
GetSQLValueString($_POST['solicitorName'], "text"),
GetSQLValueString($_POST['solicitorDetail'], "text"));
mysql_select_db($database_speedycms, $speedycms);
$Result1 = mysql_query($insertSQL, $speedycms) or die(mysql_error());
}
?>
any help would be appreciated... thanks and happy New Year!
dont worry i found a solution... decided not to use code i am not familiar with!
thanks for checking tho!
if (array_key_exists('solicitor',$_POST)) {
$solicitorName = $_POST['solicitorName'];
echo "The record for <b>$solicitorName</b> has been successfully added to the database.<p>
<a href='#' class='form'>View details</a><p>
<a href='instructus.php' class='form'>Create a new record</a>
";
exit;
};
精彩评论