編集ユーザーに問題があります。送信ボタンをクリックすると、「SQL 構文にエラーがあります。MySQL サーバーのバージョンに対応するマニュアルを参照して、1 行目の近くで使用する正しい構文を確認してください」というエラー コードが表示されます。それ。私のコードで何が起こったのかわかりません。私はそれを何度もデバッグしようとします。
<?php
//set session start
session_start();
function renderForm($UID,$Username,$Unitno,$Cont,$PW,$UEmail,$UPay,$JD,$PD)
{?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><link href="styles/style1.css" media="screen" rel="stylesheet" title="CSS" type="text/css" /></head><body><!-- Begin Container -->
<div id="container">
<!-- Begin Masthead -->
<div id="masthead">
</div>
<!-- End Masthead -->
<!-- Begin Navigation -->
<div id="navigation">
<ul>
<li><a href="homepage.php">Home Page</a></li>
<li><a href="notice.php">Notice</a></li>
<li><a href="feedback.php">Feedback</a></li>
<li><a href="user.php">User</a></li>
<li><a href="logout.php">Logout</a></li>
</ul>
</div>
<!-- End Navigation -->
<!-- Begin Content -->
<div id="content">
<!-- #BeginEditable "content" -->
<h1>Edit User</h1>
<hr/>
You are on:
<a href="user.php">User</a>
<br/>
<form action="" method="post">
<table align="center">
<tr>
<p align = "center"><strong>User ID: </strong> <?php echo $UID?></p><br/>
<td align = "right">
<strong>User Name: </strong> <input type="text" name="UserName" value = "<?php echo $Username; ?>" /><br/>
<strong>Unit No: </strong> <input type="text" name="UnitNo" value = "<?php echo $Unitno; ?>" /><br/>
<strong>Contact: </strong> <input type="text" name="Contact" value = "<?php echo $Cont; ?>" /><br/>
<strong>Password: </strong> <input type="text" name="Password" value = "<?php echo $PW; ?>" /><br/>
<strong>Email: </strong> <input type="text" name="UserEmail" value = "<?php echo $UEmail; ?>" /><br/>
<strong>User Pay: </strong> <input type="text" name="UPayment" value = "<?php echo $UPay; ?>" /><br/>
<strong>Join Date: </strong> <input type="text" name="JoinDate" value = "<?php echo $JD; ?>" /><br/>
<strong>Pay Date: </strong> <input type="text" name="PayDate" value = "<?php echo $PD; ?>" /><br/>
<input type="submit" name="submit" value="Submit">
</td>
</tr></table>
<br/>
<hr/>
</div>
<!-- End Content -->
<!-- Begin Footer -->
<div id="footer">
<p>
Copyright © 2012 Condominium Management. All Rights Reserved.
</p>
</div>
<!-- End Footer -->
</div>
<!-- End Container -->
</body>
</html><?php
include ("connection_db.php");
if(isset($_POST['submit']))
{
if (is_numeric($_POST['UID']))
{
$UserID = $_POST['UserID'];
$UserName= mysql_real_escape_string(htmlspecialchars($_POST['UserName']));
$UnitNo = mysql_real_escape_string(htmlspecialchars($_POST['UnitNo']));
$Contact = mysql_real_escape_string(htmlspecialchars($_POST['Contact']));
$Password= mysql_real_escape_string(htmlspecialchars($_POST['Password']));
$UEmail = mysql_real_escape_string(htmlspecialchars($_POST['UserEmail']));
$UPayment = mysql_real_escape_string(htmlspecialchars($_POST['UPayment']));
$JoinDate= mysql_real_escape_string(htmlspecialchars($_POST['JoinDate']));
$PayDate = mysql_real_escape_string(htmlspecialchars($_POST['PayDate']));
}
else
{
$sql = "UPDATE User SET UserName='$UserName', UnitNo='$UnitNo', Contact='$Contact', Password='$Password', UserEmail='$UEmail', UPayment='$UPayment', JoinDate='$JoinDate', PayDate='$PayDate' where UserID = $UserID";
mysql_query($sql) or die(mysql_error());
header("Location:user.php");
}
}
else
{
if(isset($_GET['UserID']) && is_numeric($_GET['UserID']) && $_GET['UserID']>0)
{
$uid = $_GET['UserID'];
$result = mysql_query("SELECT * FROM User Where UserID = $uid") or die (mysql_error());
$row = mysql_fetch_array($result);
if($row)
{
$UID = $row['UserID'];
$Username = $row['UserName'];
$Unitno = $row['UnitNo'];
$Cont = $row['Contact'];
$PW = $row['Password'];
$UEmail = $row['UserEmail'];
$UPay = $row['UPayment'];
$JD = $row['JoinDate'];
$PD = $row['PayDate'];
renderForm($UID, $Username, $Unitno, $Cont, $PW, $UEmail, $UPay, $JD, $PD, '');
}
else
{
echo "No result";
}
}
else
{
echo 'Error';
}
}?>