我正在创建一个仅限基本会员的网站,我的一个页面用于从管理员视图中编辑用户的信息。它访问名为contacts的数据库,然后访问表tblUsers,但是当它最终编辑它不保存的信息时,它就在某个地方。
<?php
include("main.php");
connectDB();
//check for submit being pressed
if(isset($_POST['submit']))
{ //check for empty fields
if($_POST['fName']!="" && $_POST['lName']!="" && $_POST['uName']!="" && $_POST['email']!="" && $_POST['address']!="" && $_POST['city']!="" && $_POST['state']!="" && $_POST['zip']!="" && $_POST['phone']!="" && $_POST['signup']!="")
{
$SQL="Update tblUsers SET firstName='".$_POST['fName']."', lastName='".$_POST['lName']."',userName='".$_POST['uName']."', email='".$_POST['email']."', address='".$_POST['address']."', city='".$_POST['city']."', state='".$_POST['state']."', zip='".$_POST['zip']."', phone='".$_POST['phone']."', signupDate='".$_POST['signup']."' WHERE userID=".$_POST['userID'];
$response=mysql_query($SQL);
//redirect with status update
header("Location:editMember.php?id=".$_POST['userID']."&status=1");
}
else
{ //redirect with status update
header("Location:editMember.php?id=".$_POST['userID']."&status=2");
}
}
//check for ID, if none redirect
if($_GET['id']=="")
{
header("Location:adminView.php");
exit;
}
//function to display form
function displayForm($strMessage, $userid, $response="")
{
echo "<center><strong>" . $strMessage . "</strong></center><br><br>";
echo "<form method=\"post\" action=\"" . $_SERVER['PHP_SELF'] . "\">\n";
echo "<table>\n";
echo "<tr>\n";
echo "<td>\n";
echo "First Name: <input type=\"text\" name=\"fName\" value=\"" . mysql_result($response,0,"firstName") . "\">\n";
echo "</td>\n";
"</tr>\n";
echo "<tr>\n";
echo "<td>\n";
echo "Last Name: <input type=\"text\" name=\"lName\" value=\"" . mysql_result($response,0,"lastName") . "\">\n";
echo "</td>\n";
"</tr>\n";
echo "<tr>\n";
echo "<td>\n";
echo "Username: <input type=\"text\" name=\"uName\" value=\"" . mysql_result($response,0,"username") . "\">\n";
echo "</td>\n";
"</tr>\n";
echo "<tr>\n";
echo "<td>\n";
echo "Email: <input type=\"text\" name=\"email\" value=\"" . mysql_result($response,0,"email") . "\">\n";
echo "</td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td>\n";
echo "Address: <input type=\"text\" name=\"address\" value=\"" . mysql_result($response,0,"address") . "\">\n";
echo "</td>\n";
"</tr>\n";
echo "<tr>\n";
echo "<td>\n";
echo "City: <input type=\"text\" name=\"city\" value=\"" . mysql_result($response,0,"city") . "\">\n";
echo "</td>\n";
"</tr>\n";
echo "<tr>\n";
echo "<td>\n";
echo "State: <input type=\"text\" name=\"state\" value=\"" . mysql_result($response,0,"state") . "\">\n";
echo "</td>\n";
"</tr>\n";
echo "<tr>\n";
echo "<td>\n";
echo "Zip: <input type=\"text\" name=\"zip\" value=\"" . mysql_result($response,0,"zip") . "\">\n";
echo "</td>\n";
"</tr>\n";
echo "<tr>\n";
echo "<td>\n";
echo "Phone Number: <input type=\"text\" name=\"phone\" value=\"" . mysql_result($response,0,"phone") . "\">\n";
echo "</td>\n";
"</tr>\n";
echo "<tr>\n";
echo "<td>\n";
echo "Sign-up Date: <input type=\"text\" name=\"signup\" value=\"" . mysql_result($response,0,"signupDate") . "\">\n";
echo "</td>\n";
"</tr>\n";
echo "<tr>\n";
echo "<td>\n";
echo "<center><input type=\"submit\" value=\"submit\" name=\"submit\"/></center>\n";
echo "</td>\n";
echo "</tr>\n";
echo "</table>\n";
echo "</form>\n";
}
//status switch to show message if successful edit
switch($_GET['status'])
{
case 1:
$strMessage="Changes have been saved";
break;
case 2:
$strMessage="All fields are required.";
break;
default:
$strMessage="Edit users.";
}
//query to show details of a user with specified userID
$SQL="SELECT * FROM tblusers WHERE userid=".$_GET['id'];
$response=mysql_query($SQL);
if($response && mysql_num_rows($response) > 0)
{
displayForm($strMessage,$_GET['id'],$response);
}
else
{
header("Location:adminView.php");
}
?>
<html>
<style type="text/css">
table {border: 1px solid black; margin-left:auto;
margin-right:auto;}
tr {border: 1px solid black}
td {border: 1px solid black;}
body {background-color: orange;}
*{font-family:Arial;}
</style>
<body>
</body>
</html>
答案 0 :(得分:0)
userID正在寻找一个已发布的值,但从未在表单中发布,因此没有任何反应,问题已解答。