php一个更新记录的代码 不指定

Else , 2006/06/14 18:14 , 代码片段,演示也有 , Comments(0) , Reads(4033) , Via Original
<?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());
}
?>
Tags: , ,
Add a comment

Nickname

Site URI

Email

Enable HTML Enable UBB Enable Emots Hidden Remember [Login] [Register]