RaythMistwalker Posted January 11, 2010 Share Posted January 11, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/188093-really-strange-and-weird/ Share on other sites More sharing options...
p2grace Posted January 11, 2010 Share Posted January 11, 2010 I don't see where you are specifying the user status in the query. If it isn't specified, it'll set it to the default (0). Quote Link to comment https://forums.phpfreaks.com/topic/188093-really-strange-and-weird/#findComment-993021 Share on other sites More sharing options...
RaythMistwalker Posted January 11, 2010 Author Share Posted January 11, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/188093-really-strange-and-weird/#findComment-993025 Share on other sites More sharing options...
mikesta707 Posted January 11, 2010 Share Posted January 11, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/188093-really-strange-and-weird/#findComment-993030 Share on other sites More sharing options...
p2grace Posted January 11, 2010 Share Posted January 11, 2010 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'); Quote Link to comment https://forums.phpfreaks.com/topic/188093-really-strange-and-weird/#findComment-993032 Share on other sites More sharing options...
RaythMistwalker Posted January 11, 2010 Author Share Posted January 11, 2010 yeah i just noticed that when i started echoing what the form was setting as variables and noticed that $newstatus wasn't setting correctly cos of a capital. Thanks guys Quote Link to comment https://forums.phpfreaks.com/topic/188093-really-strange-and-weird/#findComment-993036 Share on other sites More sharing options...
RaythMistwalker Posted January 11, 2010 Author Share Posted January 11, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/188093-really-strange-and-weird/#findComment-993075 Share on other sites More sharing options...
mikesta707 Posted January 11, 2010 Share Posted January 11, 2010 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()); } Quote Link to comment https://forums.phpfreaks.com/topic/188093-really-strange-and-weird/#findComment-993077 Share on other sites More sharing options...
RaythMistwalker Posted January 11, 2010 Author Share Posted January 11, 2010 EDIT: Fatal error: Call to undefined function now() in /home/pureclas/public_html/wordpress/wp-content/plugins/user_admin.php on line 35 erm? im sure i used now() before to get the time Quote Link to comment https://forums.phpfreaks.com/topic/188093-really-strange-and-weird/#findComment-993101 Share on other sites More sharing options...
mikesta707 Posted January 11, 2010 Share Posted January 11, 2010 NOW() is a mysql function. you are thinking of time() //wrong //$time = now(); //right $time = time(); Quote Link to comment https://forums.phpfreaks.com/topic/188093-really-strange-and-weird/#findComment-993133 Share on other sites More sharing options...
RaythMistwalker Posted January 11, 2010 Author Share Posted January 11, 2010 ah right k. thanks again guys Quote Link to comment https://forums.phpfreaks.com/topic/188093-really-strange-and-weird/#findComment-993156 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.