I am creating a basic members only website, and one of my pages is meant to edit a user's information from an admin view. It accesses the the database named contacts, and then the table tblUsers, but somewhere along the line when it finally goes to edit the info it doesn't save.
<?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>