2 Replies - 624 Views - Last Post: 05 September 2012 - 05:30 PM Rate Topic: -----

#1 matt12345  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 35
  • Joined: 08-June 12

Form not working

Posted 03 September 2012 - 09:43 AM

On this form of mine, written in PHP, several things are not happening as planned. The first thing is that the text fields won't retain their text if I click the "Update" button. This is regardless of if the form processes or not. It should retain it's values regardless. For example, if my first name is "Matt," and I change it to "Matthew," I'd assume the page refresh upon clicking "Update" will retain the "Matthew" I entered in. But instead, it resets to "Matt." Second, the form won't process the error checks on the script. It will skip down to the "An error has occurred" message instead of processing. Third, it won't process the form if the fields are entered correctly. I've been stuck on this for days, and cannot figure out why this isn't working. Here is my form:


<?php
error_reporting (E_ALL ^ E_NOTICE);
session_start();
$userid = $_SESSION['userid7906'];
$username = $_SESSION['username7906'];
$email = $_SESSION['email7906'];
$one = $_SESSION['yes7906'];
$zero = $_SESSION['no7906'];
?>
<!DOCTYPE html>

<html>
<head>
    <title>Profile Settings</title>
    <meta http-equiv="Content=Type" content="text/html; charset=utf-8" />
    <LINK REL=StyleSheet HREF="./css/profile_settings.css" TYPE="text/css" MEDIA=screen>
</head>
<body>
    <?php

$info = $_COOKIE['user7906']." <a href='./logout.php'>Log Out</a> <a href='./memberpage.php'>Home</a> <b><a href='./profile.php?user=$_COOKIE[user7906]'>Profile</a></b> > Edit <a href='./search.php'>User Search</a> <a href='./account.php'>Account</a> <br/><hr/>";
$info2 = $_COOKIE['user7906']." <a href='./logout.php'>Log Out</a> <a href='./memberpage.php'>Home</a> <b><a href='./profile.php?user=$username'>Profile</a></b> > Edit <a href='./search.php'>User Search</a> <a href='./account.php'>Account</a> <br/><hr/>";
if (isset($_COOKIE['user7906']) && isset($_COOKIE['pass7906']) && isset($_COOKIE['email7906'])) {
                            echo $info."<br/>";
    
                            if (isset($_COOKIE['no7906'])) {
                                header("Location: ./profile.php?user=$_COOKIE[user]");
                            }
                            else { 
                                require('./connect.php');
                                $fgh = mysql_query("SELECT * FROM `users` WHERE username='$_COOKIE[user7906]'");
                                $abc = mysql_num_rows("$fgh");
                                if ($abc !== 0) {
                                
                                    $osu = mysql_fetch_assoc($fgh);
                                    $harv = $osu['id'];
                                    $usr = $osu['username'];
                                    
                                        $et = mysql_query("SELECT * FROM `profiles` WHERE users_id='$harv'");
                                        $elm = mysql_num_rows($et);
                                            if ($elm !== 0) {
                                            
                                                $c = mysql_fetch_assoc($et);
                                                $mm = $c['email'];
                                                $bio = $c['about'];
                                                $fnm = $c['first_name'];
                                                $lnm = $c['last_name'];
                                                $lc4 = $c['location'];
                                                
                                                  
                                                echo "<center><b>Profile Settings</b></center><br/><br/>";
                                                
                                                ?><center>
                                                <form action='./profile_settings.php' method='POST' name='lp' />
                                                <table>
                                                <tr>
                                                    <td>First Name:</td>
                                                    <td><input type='text' name='fn' value="<?php if(isset($go)==='Update'){echo '$_REQUEST[fn]';}else{echo $fnm;} ?>" /><br/></td>
                                                </tr>
                                                <tr>
                                                    <td>Last Name:</td>
                                                    <td><input type='text' name='ln' value="<?php if(isset($go)==='Update'){echo '$_REQUEST[ln]';}else{echo $lnm;}?>" /><br/></td>
                                                </tr>
                                                <tr>
                                                    <td>Email:</td>
                                                    <td><input type='text' name='email' value="<?php if(isset($go)==='Update'){echo '$_REQUEST[email]';}else{echo $mm;}?>" /><br/></td>
                                                </tr>
                                                <tr>
                                                    <td>about:</td>
                                                    <td><input type='text' name='about' value="<?php if(isset($go)==='Update'){echo '$_REQUEST[about]';}else{echo $bio;}?>" /><br/></td>
                                                </tr>
                                                <tr>
                                                    <td>Location:</td>
                                                    <td><input type='text' name='locate' value="<?php if(isset($go)==='Update'){echo '$_REQUEST[locate]';}else{echo $lc4;}?>" /><br/></td>
                                                </tr>
                                                </table>
                                                    <center><input type='submit' name='go' value='Update' /> <?php echo "<a href='./profile.php?user=$_COOKIE[user7906]'>Cancel</a>"; ?></center>
                                                </center></form>
                                                
                                                
                                                <?php
                                                $go = $_POST['go'];
                                                $fn = $_POST['fn'];
                                                $ln = $_POST['ln'];
                                                $em = trim(strtolower($_POST['email']));
                                                $ab = $_POST['about'];
                                                $lc = $_POST['locate'];
                                                
                                                
                                                
                                                
                                                if (isset($go)) {
                                                
                                                
                                                    if ((empty($fn)) === false && (empty($ln)) === false && (empty($em)) === false && (empty($ab)) === false && (empty($lc)) === false && (strlen($em) > 6) && (strstr($em, "@")) == false && (strstr($em, ".")) == false) {
                                                    
                                                        
                                                        require("./connect.php");
                                                        $update = mysql_query("UPDATE `profiles` SET first_name='$fn' WHERE users_id='$harv' ");
                                                        $update2 = mysql_query("UPDATE `profiles` SET last_name='$ln' WHERE users_id='$harv' ");
                                                        $update3 = mysql_query("UPDATE `profiles` SET email='$em' WHERE users_id='$harv' ");
                                                        $update4 = mysql_query("UPDATE `profiles` SET about='$ab' WHERE users_id='$harv' ");
                                                        $update5 = mysql_query("UPDATE `profiles` SET location='$lc' WHERE users_id='$harv' ");

                                                        echo '<br/>Profile updated successfully';
                                                        
                                                    
                                                    
                                                   
                                                
                                               
                                                
                                                    }
                                                    elseif (!isset($_POST)) {
                                                    echo '<br/><center>Please fill out this form.</center>';
                                                    }
                                                    elseif (isset($fn)==='') {
                                                    echo '<br/><center>Enter your first name.</center>';
                                                    }
                                                    elseif (isset($ln)==='') {
                                                    echo '<br/><center>Enter your last name.</center>';
                                                    }
                                                    elseif (isset($em)==='') {
                                                    echo '<br/><center>Enter your email.</center>';
                                                    }
                                                    elseif ((strlen($em) < 7) || (strstr($em, "@")) === false || (strstr($em, ".")) === false) {
                                                    echo '<br/><center>Invalid email</center>';
                                                    }
                                                    elseif (isset($ab)==='') {
                                                    echo '<br/><center>Write something about yourself.</center>';
                                                    }
                                                    elseif (isset($lc)==='') {
                                                    echo '<br/><center>Enter your location.</center>';
                                                    }
                                                    else {
                                                    echo '<center>An error has occured.</center>';
                                                    }
                                                
                                               
                                                
                                                }
                                                
                                            
                                            }
                                            else {
                                            header("Location: ./profile.php?user=$_COOKIE[user7906]");
                                            }
                                
                                }
                                else {
                                echo '<center>An error has occured.</center>';
                                }
                                
                                
                          
    }
        
        
        

    
    
    
    }
    elseif(isset($username) && isset($userid) && isset($email)) {
                            echo $username.$info2."<br/>";
        
        
                           
                                require('./connect.php');
                                $fgh = mysql_query("SELECT * FROM `users` WHERE username='$username'");
                                $abc = mysql_num_rows($fgh);
                                if ($abc !== 0) {
                                
                                    $osu = mysql_fetch_assoc($fgh);
                                    $harv = $osu['id'];
                                    $usr = $osu['username'];
                                    
                                        $et = mysql_query("SELECT * FROM `profiles` WHERE users_id='$harv'");
                                        $elm = mysql_num_rows($et);
                                            if ($elm !== 0) {
                                            
                                                $c = mysql_fetch_assoc($et);
                                                $mm = $c['email'];
                                                $bio = $c['about'];
                                                $fnm = $c['first_name'];
                                                $lnm = $c['last_name'];
                                                $lc4 = $c['location'];
                                                
                                                echo "<center><b>Profile Settings</b></center><br/><br/>";
                                                
                                                ?>
                                                
                                                <form action='./profile_settings.php' method='POST' name='lp' /><center>
                                                
                                                
                                                <table>
                                                <tr>
                                                    <td>First Name:</td>
                                                    <td><input type='text' name='fn' value="<?php if(isset($go)==='Update'){echo '$_REQUEST[fn]';}else{echo $fnm;} ?>" /><br/></td>
                                                </tr>
                                                <tr>
                                                    <td>Last Name:</td>
                                                    <td><input type='text' name='ln' value="<?php if(isset($go)==='Update'){echo '$_REQUEST[ln]';}else{echo $lnm;}?>" /><br/></td>
                                                </tr>
                                                <tr>
                                                    <td>Email:</td>
                                                    <td><input type='text' name='email' value="<?php if(isset($go)==='Update'){echo '$_REQUEST[email]';}else{echo $mm;}?>" /><br/></td>
                                                </tr>
                                                <tr>
                                                    <td>about:</td>
                                                    <td><input type='text' name='about' value="<?php if(isset($go)==='Update'){echo '$_REQUEST[about]';}else{echo $bio;}?>" /><br/></td>
                                                </tr>
                                                <tr>
                                                    <td>Location:</td>
                                                    <td><input type='text' name='locate' value="<?php if(isset($go)==='Update'){echo '$_REQUEST[locate]';}else{echo $lc4;}?>" /><br/></td>
                                                </tr>
                                                </table>
                                                    <center><input type='submit' name='go' value='Update' /> <?php echo "<a href='./profile.php?user=$username'>Cancel</a>"; ?></td></center>
                                                
                                                </center></form>
                                                
                                                
                                                <?php
                                                $go = $_POST['go'];
                                                $fn = $_POST['fn'];
                                                $ln = $_POST['ln'];
                                                $em = trim(strtolower($_POST['email']));
                                                $ab = $_POST['about'];
                                                $lc = $_POST['locate'];
                                                
                                                
                                                
                                                
                                                if (isset($go)) {
                                                
                                                
                                                    if ((empty($fn)) === false && (empty($ln)) === false && (empty($em)) === false && (empty($ab)) === false && (empty($lc)) === false && (strlen($em) > 6) && (strstr($em, "@")) == false && (strstr($em, ".")) == false) {
                                                    
                                                        
                                                        require("./connect.php");
                                                        $update = mysql_query("UPDATE `profiles` SET first_name='$fn' WHERE users_id='$userid' ");
                                                        $update2 = mysql_query("UPDATE `profiles` SET last_name='$ln' WHERE users_id='$userid' ");
                                                        $update3 = mysql_query("UPDATE `profiles` SET email='$em' WHERE users_id='$userid' ");
                                                        $update4 = mysql_query("UPDATE `profiles` SET about='$ab' WHERE users_id='$userid' ");
                                                        $update5 = mysql_query("UPDATE `profiles` SET location='$lc' WHERE users_id='$userid' ");

                                                        echo '<br/>Profile updated successfully';
                                                        
                                                    
                                                    
                                                   
                                                
                                               
                                                
                                                    }
                                                    elseif (!isset($_POST)) {
                                                    echo '<br/><center>Please fill out this form.</center>';
                                                    }
                                                    elseif (isset($fn)==='') {
                                                    echo '<br/><center>Enter your first name.</center>';
                                                    }
                                                    elseif (isset($ln)==='') {
                                                    echo '<br/><center>Enter your last name.</center>';
                                                    }
                                                    elseif (isset($em)==='') {
                                                    echo '<br/><center>Enter your email.</center>';
                                                    }
                                                    elseif ((strlen($em) < 7) || (strstr($em, "@")) === false || (strstr($em, ".")) === false) {
                                                    echo '<br/><center>Invalid email</center>';
                                                    }
                                                    elseif (isset($ab)==='') {
                                                    echo '<br/><center>Write something about yourself.</center>';
                                                    }
                                                    elseif (isset($lc)==='') {
                                                    echo '<br/><center>Enter your location.</center>';
                                                    }
                                                    else {
                                                    echo '<center>An error has occured.</center>';
                                                    }
                                                
                                               
                                                
                                                }
                                                
                                            
                                            }
                                            else {
                                            header("Location: ./profile.php?user=$username");
                                            }
                                
                                }
                                else {
                                echo '<center>An error has occured.</center>';
                                }
                                
                                
                          
    
        
        
        
    }
    else {
        echo "Please log in for access to this page. Log in <a href='./login.php'>here</a>.";
    }
    
    ?>
</body>
</html>




A solution, in PHP, to this would be greatly appreciated. Thanks.

Is This A Good Question/Topic? 0
  • +

Replies To: Form not working

#2 matt12345  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 35
  • Joined: 08-June 12

Re: Form not working

Posted 03 September 2012 - 09:59 AM

2 other forms that are experiencing similar issues are forms of mine that allow the user to edit their email and username. Thanks.

email form: It won't retain altered text value upon refresh. Also, it won't process error correctly. Lastly, it won't update if no errors are present.


<?php
error_reporting (0);
session_start();
$userid = $_SESSION['userid7906'];
$username = $_SESSION['username7906'];
$email = $_SESSION['email7906'];
$one = $_SESSION['yes7906'];
$zero = $_SESSION['no7906'];
?>
<!DOCTYPE html>

<html>
<head>
    <title>Edit Email</title>
    <meta http-equiv="Content=Type" content="text/html; charset=utf-8" />
    <LINK REL=StyleSheet HREF="./css/editemail.css" TYPE="text/css" MEDIA=screen>
</head>
<body>
    <?php

$info = $_COOKIE['user7906']." <a href='./logout.php'>Log Out</a> <a href='./memberpage.php'>Home</a> <a href='./profile.php?user=$_COOKIE[use7906]'>Profile</a> <a href='./search.php'>User Search</a> <b><a href='./account.php'>Account</a></b> > Edit Email<br/><hr/>";
$info2 = $_COOKIE['user7906']." <a href='./logout.php'>Log Out</a> <a href='./memberpage.php'>Home</a> <a href='./profile.php?user=$username'>Profile</a> <a href='./search.php'>User Search</a> <b><a href='./account.php'>Account</a></b> > Edit Email<br/><hr/>";

if (isset($_COOKIE['user7906']) && isset($_COOKIE['pass7906']) && isset($_COOKIE['email7906'])) {
    echo $info;
    echo "<br/><br/>";
    ?>
            <form action='./editemail.php' method='post'>
            <center><table>
                <td></td>
            <tr>
                <td>Email:</td>
                <td><input type='text' name='user' value='<?php if(isset($_POST['submit'])==='Update'){echo '$_REQUEST[user]';}else{echo $email;}?>' /></td>
            </tr>
             <tr>
                <td><br/></td>
                <td></td>
            </tr>
            <tr>
                <td>Password Verificaton:</td>
                <td><input type='password' name='password' value=''/></td>
            </tr>
            <tr>
                <td></td>
                <td><input type='submit' name='submit' value='Update' /></td>
            </tr>
            </table></center>
            </form><?php
            
        
            if (isset($_POST['submit']) === true) {
                
                $user = trim(strtolower($_POST['user']));
                $password = $_POST['password'];

                    if ( (empty($user)) === false && (empty($password)) === false && (strlen($user)) > 6 && (strstr($user, "@")) && (strstr($user, "."))) {
                    
                    /*db*/
                    
                    require('./connect.php');
                    
                    
                    /*check if password is correct*/
                    
                    $password = md5(md5("secret salt value".$password."secret salt value"));
                    
                    $query = mysql_query("SELECT * FROM `users` WHERE username='$_COOKIE[user7906]' AND password='$password'");
                    $numrows = mysql_num_rows($query);
                    if ($numrows === 1) { /*checks if exact*/
                        $row = mysql_fetch_assoc($query);
                        $dbuser = $row['username'];
                        $dbpass = $row['password'];
                        
                    
                            /*check if email is already taken*/
                            $taken = mysql_query("SELECT * FROM `users` WHERE email='$user'");
                            $numrows2 = mysql_num_rows($taken);
                            if ($numrows2 === 0) {
                                
                                /*update email address*/
                                    $update_email = mysql_query("UPDATE users SET email='$user' WHERE username='$dbuser' AND password='$dbpass' "); /*or could use cookie/session data/post data*/
                                    $_COOKIE['email7906'] = setcookie('email', $user, time()+3600);
                                            
                                            if (isset($update_email) === true) {
                                            
                                                header('Location: ./account.php');
                                                mysql_close();
                                            }
                                            else {
                                            echo 'An error has occured. Email not updated.';
                                            }
                                           
                                        
                            }
                            else {
                                echo 'Email taken';
                            }
                            
                            
                    }
                    else {
                        echo '<br/>Password is incorrect';
                    }
                    
                    
                    
                }
                elseif ( (empty($user)) === true ) {
                    echo '<br/>Please enter a new email.';
                }
                elseif ( (empty($user2)) === true ) {
                    echo '<br/>Please verify your new email.';
                }
                elseif ( (empty($password)) === true ) {
                    echo '<br/>Please enter your password.';
                }
                elseif ( $user !== $user2 ) {
                    echo '<br/>Emails do not match.';
                }
                elseif ( (strlen($user)) <= 6 ) {
                    echo '<br/>Email is too short.';
                }
                elseif ( (strlen($user2)) <= 6 ) {
                    echo '<br/>Verification email is too short.';
                }
                elseif ( (!strstr($user, "@")) || (!strstr($user, ".")) ) {
                    echo '<br/>Email(s) invalid';
                }
                else {
                
                }
                
                
                
            }
            else {

            }
            
            
            
    }
    elseif(isset($username) && isset($userid) && isset($email)) {
            echo $username.$info2;
            echo "<br/><br/>";
            ?>
            <form action='./editemail.php' method='post'>
            <center><table>
                <td></td>
            <tr>
                <td>Email:</td>
                <td><input type='text' name='user' value='<?php if(isset($_POST['submit'])==='Update'){echo '$_REQUEST[user]';}else{echo $email;}?>' /></td>
            </tr>
             <tr>
                <td><br/></td>
                <td></td>
            </tr>
            <tr>
                <td>Password Verificaton:</td>
                <td><input type='password' name='password' value=''/></td>
            </tr>
            <tr>
                <td></td>
                <td><input type='submit' name='submit' value='Update' /></td>
            </tr>
            </table></center>
            </form><?php
            
        
                if (isset($_POST['submit']) === true) {
                
                $user = trim(strtolower($_POST['user']));
                $password = $_POST['password'];

                    if ( (empty($user)) === false && (empty($password)) === false && (strlen($user)) > 6 && (strstr($user, "@")) && (strstr($user, ".")) && (strlen($user)) <= 6) {
                        
                        /*db*/
                        
                        require('./connect.php');

                      
                        
                    /*check if password is correct*/
                    
                    $password = md5(md5("secret salt value".$password."secret salt value"));
                    
                    $query = mysql_query("SELECT * FROM `users` WHERE username='$username' AND password='$password'");
                    $numrows = mysql_num_rows($query);
                    if ($numrows === 1) {
                        $row = mysql_fetch_assoc($query);
                        $dbid = $row['id'];
                        $dbuser = $row['username'];
                        $dbpass = $row['password'];
                        
                    
                            /*check if email is already taken*/
                        
                            $taken = mysql_query("SELECT * FROM `users` WHERE email='$user'");
                            $numrows2 = mysql_num_rows($taken);
                            if ($numrows2 === 0) {
                                
                                /*update email address*/
                                    $update_email = mysql_query("UPDATE users SET email='$user' WHERE username='$dbuser' AND password='$dbpass' "); /*or could use cookie/session data/post data*/
                                    $_SESSION['email'] = $user;    
                                        if (isset($update_email) === true) {
                                            header('Location: ./account.php');
                                            }
                                            else {
                                            echo $form.'An error has occured. Email not updated.';
                                            }
                                        
                                        
                            }
                            else {
                                echo 'Email taken';
                            }
                    }
                    else {
                        echo '<br/>Password is incorrect';
                    }
                    
                    
                    }
                    elseif ( (empty($user)) === true ) {
                        echo '<br/>Please enter a new email.';
                    }
                    elseif ( (empty($password)) === true ) {
                        echo '<br/>Please enter your password.';
                    }
                    elseif ( (strlen($user)) <= 5 ) {
                        echo '<br/>Email is too short.';
                    }
                    elseif ( (!strstr($user, "@")) || (!strstr($user, ".")) || (strlen($user)) <= 6 ) {
                        echo '<br/>Email invalid';
                    }
                    else {
                    
                    }
                
                
                
            }
            else {

            }
            
        
        
        
        }
        else {
            echo "Please log in for access to this page. Log in <a href='./login.php'>here</a>.";
        }
        
    ?>
</body>
</html>




form for editing username: Won't retain text value if altered.


<?php
error_reporting (0);
session_start();
$userid = $_SESSION['userid7906'];
$username = $_SESSION['username7906'];
$email = $_SESSION['email7906'];
$one = $_SESSION['yes7906'];
$zero = $_SESSION['no7906'];
?>
<!DOCTYPE html>

<html>
<head>
    <title>Edit Username</title>
    <meta http-equiv="Content=Type" content="text/html; charset=utf-8" />
    <LINK REL=StyleSheet HREF="./css/edituser.css" TYPE="text/css" MEDIA=screen>
</head>
<body>
    <?php

$info2 = $_COOKIE['user7906']." <a href='./logout.php'>Log Out</a> <a href='./memberpage.php'>Home</a> <a href='./profile.php?user=$_COOKIE[user7906]'>Profile</a> <b><a href='./account.php'>Account</a></b> > Edit Username <br/><hr/>";
$info = $_COOKIE['user7906']." <a href='./logout.php'>Log Out</a> <a href='./memberpage.php'>Home</a> <a href='./profile.php?user=$username'>Profile</a> <b><a href='./account.php'>Account</a></b> > Edit Username <br/><hr/>";


if (isset($_COOKIE['user7906']) && isset($_COOKIE['pass7906']) && isset($_COOKIE['email7906'])) {
    echo $info2;
    echo "<br/><br/>";?>
            <form action='./edituser.php' method='post'>
            <center><table>
                <td></td>
            <tr>
                <td>Username:</td>
                <td><input type='text' name='user' value='<?php if(isset($_POST['submit'])==='Update'){echo '$_REQUEST[user]';}else{echo $_COOKIE['user7906'];}?>' /></td>
            </tr>
             <tr>
                <td><br/></td>
                <td></td>
            </tr>
            <tr>
                <td>Password Verificaton:</td>
                <td><input type='password' name='password' value=''/></td>
            </tr>
            <tr>
                <td></td>
                <td><input type='submit' name='submit' value='Update' /></td>
            </tr>
            </table></center>
            </form>
            <?php
        
            if (isset($_POST['submit']) === true) {
                
                $user = trim(strtolower($_POST['user']));
                $password = $_POST['password'];
                
                if ((empty($user)) === false && (empty($password)) === false) {
                    /*db*/
                    
                    require("./connect.php");
                
                    $password = md5(md5("secret salt value".$password."secret salt value"));
                    /*make sure password is correct*/
                    
                    $query = mysql_query("SELECT * FROM `users` WHERE username='$_COOKIE[user7906]' AND password='$password'");
                    $numrows = mysql_num_rows($query);
                    if ($numrows === 1) { /*checks if exact*/
                        $row = mysql_fetch_assoc($query);
                        $dbid = $row['id'];
                        $dbuser = $row['username'];
                        $dbpass = $row['password'];
                        
                        /*check if username is already taken*/
                        
                        $taken = mysql_query("SELECT * FROM `users` WHERE username='$user'");
                        $numrows2 = mysql_num_rows($taken);
                        if ($numrows2 === 0) { /*check if anything similar exits...not checking if exact match appears, checks both*/
                        
                            /*update username in db table*/
                            
                            $update_username = mysql_query("UPDATE users SET username='$user' WHERE username='$_COOKIE[user7906]' AND password='$dbpass' ");
                            $_COOKIE['user7906'] = setcookie("user7906",$user,time()+3600);
                            if (isset($update_username) === true) {
                                header('Location: ./account.php');                                
                                mysql_close();
                                
                            }
                            else {
                                echo '<br/>An error has occured. Your username has not been updated.';
                            }
                            
                        }
                        else {
                        echo '<br/>Username taken';
                        }
                        
                    }
                    else {
                        echo '<br/>Password is incorrect.';
                    }
                    
                }
                elseif((empty($user)) === true){
                    echo '<br/>Enter a new username.';
                }
                elseif((empty($user)) === true){
                    echo '<br/>Enter a new username.';
                }
                elseif((empty($password)) === true){
                    echo '<br/>Please enter your password.';
                }
                
                
            }
            else {
                
            }
            
            
            
    }
    elseif(isset($username) && isset($userid) && isset($email)) {
            echo $username.$info;
            echo "<br/><br/>";
            ?><form action='./edituser.php' method='post'>
            <center><table>
                <td></td>
            <tr>
                <td>Username:</td>
                <td><input type='text' name='user' value='<?php if(isset($_POST['submit'])==='Update'){echo '$_REQUEST[user]';}else{echo $username;}?>' /></td>
            </tr>
             <tr>
                <td><br/></td>
                <td></td>
            </tr>
            <tr>
                <td>Password Verificaton:</td>
                <td><input type='password' name='password' value=''/></td>
            </tr>
            <tr>
                <td></td>
                <td><input type='submit' name='submit' value='Update' /></td>
            </tr>
            </table></center>
            </form><?php
            
        
            if (isset($_POST['submit']) === true) {
                
                $user = trim(strtolower($_POST['user']));
                $password = $_POST['password'];
                
                if ((empty($user)) === false && (empty($password)) === false) {
                    /*db*/
                    
                    require("./connect.php");

                    $password = md5(md5("secret salt value".$password."secret salt value"));
                    /*make sure password is correct*/
                    
                    $query = mysql_query("SELECT * FROM `users` WHERE username='$username' AND password='$password'");
                    $numrows = mysql_num_rows($query);
                    if ($numrows === 1) { /*checks if exact*/
                        $row = mysql_fetch_assoc($query);
                        $dbid = $row['id'];
                        $dbuser = $row['username'];
                        $dbpass = $row['password'];
                        
                        /*check if username is already taken*/
                        
                        $taken = mysql_query("SELECT * FROM `users` WHERE username='$user'");
                        $numrows2 = mysql_num_rows($taken);
                        if ($numrows2 == 0) { /*checks if anything exact AND similar exits*/
                        
                            /*update username in db table*/
                            
                            $update_username = mysql_query("UPDATE users SET username='$user' WHERE username='$dbuser' AND password='$dbpass' "); /*or could use cookie/session data/post data*/
                            $_SESSION['username7906'] = $user;
                            if (isset($update_username) === true) {
                                    header('Location: ./account.php');     
                                }
                                else {
                                echo 'An error has occured. Username not updated.';
                                }
                        
                        }
                        else {
                            echo '<br/>Username taken';
                        }
                        
                        
                    }
                    else {
                        echo '<br/>Password is incorrect.';
                    }
                    
                }
                elseif((empty($user)) === true){
                    echo '<br/>Enter a new username.';
                }
                elseif((empty($user)) === true){
                    echo '<br/>Enter a new username.';
                }
                elseif((empty($password)) === true){
                    echo '<br/>Please enter your password.';
                }
                
                
            }
            else {

            }
            
        
        
        
        }
        else {
            echo "Please log in for access to this page. Log in <a href='./login.php'>here</a>.";
        }
        
    ?>
</body>
</html>



Was This Post Helpful? 0
  • +
  • -

#3 BrairMoss  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 15
  • View blog
  • Posts: 81
  • Joined: 13-April 10

Re: Form not working

Posted 05 September 2012 - 05:30 PM

Could any of the issues be because you refer to the $username as a session, and then in the code try to pull out the data again as a cookie? I am assuming the cookies are used elsewhere, also you would need to post back in on the page in order to grab any new values set/kept. Maybe use a switch statement in this instance, with a ?failed=true or something similiar.


//BrairMoss
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1