gpt4 book ai didi

php - 为什么我的查询从未正确编辑 MySQL 表的成员?

转载 作者:行者123 更新时间:2023-11-29 21:46:41 25 4
gpt4 key购买 nike

我正在创建一个仅限成员(member)的基本网站,我的页面之一旨在从管理 View 编辑用户信息。它访问名为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>

最佳答案

userID 正在寻找发布的值,但从未在表单中发布,因此什么也没有发生,问题已得到解答。

关于php - 为什么我的查询从未正确编辑 MySQL 表的成员?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34056150/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com