无法执行更新功能.我认为我的$id赋值有问题


The cannot do the update function. I think my $id assign value something wrong

这段代码就是函数。我想从数据库中分配要更新的值。

$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);
?>

尝试这种编码。。。

如果你得到了$id的价值,那么

更换以下编码

$qry="UPDATE reservation SET PaymentProof_Slip='$image' WHERE Reservation_ID='$id'";

$qry="UPDATE reservation SET PaymentProof_Slip='".$image."' WHERE Reservation_ID='".$id."'";