Jump to content

Recommended Posts

k 2 things first.

 

<form action="" method=post>

<input type='hidden' name='id' value='<? echo $id; ?>'>

<input type='hidden' name='newstatus' value='2'>

<input type='submit' name='submit' value='Activate'></form>

<form action="" method=post>

<input type='hidden' name='id' value='<? echo $id; ?>'>

<input type='hidden' name='newstatus' value='0'>

<input type='submit' name='submit' value='Disable'></form>

 

That is my form and you can prob see what it does :)

Heres the code it activates:

function newStatus($id, $newstatus) {
    mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
    mysql_select_db(DB_NAME); 
    $qry = "UPDATE accounts SET status='$newstatus' WHERE id='$id'";
    $res = mysql_query($qry);
    $qry2 = "SELECT * FROM accounts WHERE id='$id'";
    $res2 = mysql_query($qry2);
    $info = mysql_fetch_array($res2);
    
    if ($newstatus = 0) {
       $username = $info['username'];
       delAccount($username); 
    }   
    if ($newstatus = 2) {
        $username = $info['username'];
        $password = $info['password'];
        $nicename = $username;
        $displayname = $username;
        $email = $info['email'];
        $time = now();
        require_once('../../wp-includes/class-phpass.php');
        $wp_hasher = new PasswordHash(8, TRUE);
        $pass = $wp_hasher->HashPassword($pass);
        
        $makeUserQry = "INSERT INTO wp_users(user_login, user_pass, user_nicename, user_email, user_registered, display_name) VALUES('$username','$pass','$nicename','$email','$time','$displayname')";
        $makeUser = mysql_query($makeUserQry);
        if (!$makeUser) { die("Error. Could not add user to wp_users table."); }
    }
}
if (isset($_POST['submit'])) {
    $id = $_POST['id'];
    $newStatus = $_POST['newstatus'];
    newStatus($id, $newstatus);
    exit();
}

 

For some reason no matter what button i click it just sets user status to 0 when it should set to 2 or 0.

Link to comment
https://forums.phpfreaks.com/topic/188093-really-strange-and-weird/
Share on other sites

the user status comes from the function

function newStatus($id, $newstatus) {

 

Which is set in the form

 

<input type='hidden' name='newstatus' value='2'>

 

and the function is called by

if (isset($_POST['submit'])) {
    $id = $_POST['id'];
    $newStatus = $_POST['newstatus'];
    newStatus($id, $newstatus);
    exit();
}

 

Also the default status is 1 not 0

is `status` an integer column? or a varchar column. If its an int, try removing the single quotes around the status in the update query.

 

also, to debug, try printing the value of $_POST['newstatus'] to the screen, and verify it has what you expect it to

Your variables are different.

 

Your code:

 

if (isset($_POST['submit'])) {
    $id = $_POST['id'];
    $newStatus = $_POST['newstatus'];
    newStatus($id, $newstatus);
    exit();
}

 

Should be:

 

if (isset($_POST['submit'])) {
    $id = $_POST['id'];
    $newStatus = $_POST['newstatus'];
    newStatus($id, $newStatus);
    exit();
}

 

To catch these types of issues easily, it's always a good idea to display errors while in development (development only).

 

error_reporting(E_ALL);
ini_set('display_errors','on');

k new problem (why i marked this unsolved)

 

function newStatus($id, $newstatus, $refer) {
    mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
    mysql_select_db(DB_NAME); 
    $qry = "UPDATE accounts SET status=$newstatus WHERE id='$id'";
    $res = mysql_query($qry);
    $qry2 = "SELECT * FROM accounts WHERE id='$id'";
    $res2 = mysql_query($qry2);
    $info = mysql_fetch_array($res2);
    if ($refer == 'pending') { echo "Click <a href='".$_SERVER['PHP_SELF']."?page=user_pending.php'>Here to go back</a>"; }
    if ($refer == 'disabled') { echo "Click <a href='".$_SERVER['PHP_SELF']."?page=user_disabled.php'>Here to go back</a>"; }
    if ($refer == 'active') { echo "Click <a href='".$_SERVER['PHP_SELF']."?page=user_active.php'>Here to go back</a>"; }
    
    if ($newstatus == 0) {
       $username = $info['username'];
       delAccount($username); 
    }   
    if ($newstatus == 2) {
        $username = $info['username'];
        $password = $info['password'];
        $nicename = $username;
        $displayname = $username;
        $email = $info['email'];
        $time = now();
        require_once('../../wp-includes/class-phpass.php');
        $wp_hasher = new PasswordHash(8, TRUE);
        $pass = $wp_hasher->HashPassword($pass);
        
        $makeUserQry = "INSERT INTO wp_users(user_login, user_pass, user_nicename, user_email, user_registered, display_name) VALUES('$username','$pass','$nicename','$email','$time','$displayname')";
        $makeUser = mysql_query($makeUserQry);
        if (!$makeUser) { die("Error. Could not add user to wp_users table."); }
    }
    mysql_close();
}

Thats my updated function and now it isn't putting the information into the wp_users table as it asks it to o.o

for debugging purposes, try printing the mysql error but adding it to the die clause

$makeUserQry = "INSERT INTO wp_users(user_login, user_pass, user_nicename, user_email, user_registered, display_name) VALUES('$username','$pass','$nicename','$email','$time','$displayname')";
$makeUser = mysql_query($makeUserQry);
if (!$makeUser) { die("Error. Could not add user to wp_users table. Error: " . mysql_error()); }

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.