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_update"])) && ($_POST["MM_update"] == "form2")) {
$updateSQL = sprintf("UPDATE artcat SET catname=%s, list=%s, pid=%s, `view`=%s, catcon=%s, menu=%s, ruby=%s WHERE id=%s",
GetSQLValueString($_POST['catname'], "text"),
GetSQLValueString($_POST['list'], "int"),
GetSQLValueString($_POST['pid'], "int"),
GetSQLValueString(isset($_POST['view']) ? "true" : "", "defined","1","0"),
GetSQLValueString($_POST['catcon'], "text"),
GetSQLValueString(isset($_POST['menu']) ? "true" : "", "defined","1","0"),
GetSQLValueString(isset($_POST['ruby']) ? "true" : "", "defined","1","0"),
GetSQLValueString($_POST['id'], "int"));
mysql_select_db($database_db, $db);
$Result1 = mysql_query($updateSQL, $db) or die(mysql_error());
}
?>
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_update"])) && ($_POST["MM_update"] == "form2")) {
$updateSQL = sprintf("UPDATE artcat SET catname=%s, list=%s, pid=%s, `view`=%s, catcon=%s, menu=%s, ruby=%s WHERE id=%s",
GetSQLValueString($_POST['catname'], "text"),
GetSQLValueString($_POST['list'], "int"),
GetSQLValueString($_POST['pid'], "int"),
GetSQLValueString(isset($_POST['view']) ? "true" : "", "defined","1","0"),
GetSQLValueString($_POST['catcon'], "text"),
GetSQLValueString(isset($_POST['menu']) ? "true" : "", "defined","1","0"),
GetSQLValueString(isset($_POST['ruby']) ? "true" : "", "defined","1","0"),
GetSQLValueString($_POST['id'], "int"));
mysql_select_db($database_db, $db);
$Result1 = mysql_query($updateSQL, $db) or die(mysql_error());
}
?>
mysql的函数库
php字符串函数
