SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Evangelist
    Join Date
    Apr 2009
    Location
    South Carolina
    Posts
    458
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    my if statement is not working as I expect

    I am trying to set up a strong hint that the password needs to be changed. I have created a statement of if ($cp = 'yes') { header ("Location: http://---/change_password.php"); } else {header ("Location: http://---/index.php");

    That is the short version where if the information I read from MySQL is yes I go to change the password, otherwise, I go to index.

    I suspect as a beginner, I have made a mistake. Here is the full code for this section.

    PHP Code:
        if ($u && $p && $captchchk) {
            
    $query "SELECT user_id, first_name, last_name, email, pass, chng_pass, roll FROM users_tbl WHERE user_id='$u' AND pass=SHA('$p')";        
            
    $result mysql_query ($query) or trigger_error("Either the Password or Userid are incorrect.");
            if (
    mysql_affected_rows() == 1) { // A match was made.
                
    $row mysql_fetch_array ($resultMYSQL_NUM);
                
    mysql_free_result($result);
                    
                
    $_SESSION['first_name'] = $row[1];
                
    $_SESSION['userid'] = $row[0];
                
    $_SESSION['chng_pass'] = $row[5];
                
    $_SESSION['roll'] = $row[6];
                    
                
    $cp $_SESSION['chng_pass'];
                    
    $token_id rand(100009999999);
                    
                
    $query2 "UPDATE users_tbl SET token_id = $token_id WHERE user_id = '$_SESSION[userid]'";
                
    $result2 mysql_query ($query2);
                
    $_SESSION['token_id'] = $token_id;
                    
                    
    // FIX THIS the line below may be causing problems
                    // session_regenerate_id();

    echo '<pre>',print_r($cp),'</pre>'// this reads no1

                
    if ($cp 'yes') {
                    
    header("Location: http://www.recse.org/clergy/change_password.php");
                    
    mysql_close(); // Close the database connection.
                    
    exit();

                } else {
                    
    header("Location: http://www.recse.org/clergy/index.php");
                    
    mysql_close(); // Close the database connection.
                    
    exit();
                } 
    If there is a better way to do this, let me know. I would really like to find a way that will force a password change, but all I can figure out is to take the user to the change_password.php page.
    Each day is a learning experience.

  2. #2
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    24,299
    Mentioned
    460 Post(s)
    Tagged
    8 Thread(s)
    I'm no PHP person, so forgive me if this is off track. But shouldn't

    if ($cp = 'yes')

    be

    if ($cp == 'yes')

    ?

  3. #3
    SitePoint Evangelist
    Join Date
    Apr 2009
    Location
    South Carolina
    Posts
    458
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ralph.m,

    Thanks. That fixed the immediate issue. Now to move on to the next issue as soon as I discover another of my programming errors.
    Each day is a learning experience.

  4. #4
    SitePoint Evangelist
    Join Date
    Jun 2008
    Posts
    455
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You're right Ralph.

    = sets the value where as == is a comparison.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •