0

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>
  • 1
    [Why you shouldn't use mysql_* functions in PHP](http://stackoverflow.com/q/12859942/1028804) – Memor-X Dec 03 '15 at 01:25
  • can't emphasize on this enough: check for errors in every possible way. – Funk Forty Niner Dec 03 '15 at 01:27
  • @Memor-X I understand that there may be problems with using mysql functions, however this is how I was taught to do it. I can only assume that there is a way to get this to work since it was assigned to me. This is for a basic PHP and MySQL class – Tyler Bobertson Dec 03 '15 at 01:46
  • @Fred-ii- I have tried looking for errors all day, I have been sitting here for like 3 hours not able to figure out what's going wrong, that is why I posted here. – Tyler Bobertson Dec 03 '15 at 01:47
  • Add error reporting to the top of your file(s) right after your opening ` – Funk Forty Niner Dec 03 '15 at 01:48
  • @TylerBobertson if you look at the question/answer i linked to you'll notice that `mysql_` is deprecated and is removed in later versions of PHP – Memor-X Dec 03 '15 at 02:05
  • @Fred-ii- The forced error reporting made me find out where my bug was, I was checking for userID at post, but I never posted userID in the form so it never changed anything. Thanks so much! – Tyler Bobertson Dec 03 '15 at 02:20

1 Answers1

0

userID was looking for a posted value, but was never being posted in the form so nothing happened, question answered.