此代码是函数。我想从数据库中分配值来更新。
$row_Recordset1['Reservation_ID']
是我想要更新的主键值。
function saveimage($name, $image)
{
$con=mysql_connect("localhost", "root", "");
mysql_select_db("myhomestay",$con);
echo $id=$row_Recordset1['Reservation_ID'];
$qry="UPDATE reservation SET PaymentProof_Slip='$image' WHERE Reservation_ID='$id'";
$result=mysql_query($qry, $con);
if($result)
{
echo "<br/>Image uploaded.";
}
else
{
echo "<br/>Image not uploaded.";
}
}
?>
此代码用于从数据库中检索数据。
<?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;
}
}
$colname_Recordset1 = "-1";
if (isset($_SESSION['MM_Username'])) {
$colname_Recordset1 = $_SESSION['MM_Username'];
}
mysql_select_db($database_MyHomeStay_System, $MyHomeStay_System);
$query_Recordset1 = sprintf("SELECT * FROM reservation natural join guest natural join homestay WHERE Guest_Email = %s", GetSQLValueString($colname_Recordset1, "text"));
$Recordset1 = mysql_query($query_Recordset1, $MyHomeStay_System) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
?>
答案 0 :(得分:0)
试试这个编码...
如果你有$ id值,那么
替换以下编码
$qry="UPDATE reservation SET PaymentProof_Slip='$image' WHERE Reservation_ID='$id'";
到
$qry="UPDATE reservation SET PaymentProof_Slip='".$image."' WHERE Reservation_ID='".$id."'";