3raser Posted November 23, 2009 Share Posted November 23, 2009 After filling out the information, why doesn't it say "User updated!"? <?php //user-editing //connect to database $connect = mysql_connect("$dbhost","$dbuser","$dbpassword") or die("Connection failed!"); mysql_select_db("$db") or die("Database fail!"); $name = $_SESSION['username']; //extract $extract = mysql_query("SELECT * FROM users WHERE username='$name'"); $numrows = mysql_num_rows($extract); while ($row = mysql_fetch_assoc($extract)) { $staffcheck = $row[staff]; } if ($staffcheck==2) { $user_edit = $_GET['user']; if (!$user_edit) { } else { //display data $get = mysql_query("SELECT * FROM users WHERE username='$user_edit'"); while ($row = mysql_fetch_assoc($get)) { // get data $points_c = $row['points']; $posts_c = $row['postcount']; $user_uname_c = $row['username']; $points = $_POST['points']; $posts = $_POST['posts']; $user_uname = $_POST['username']; if (!$points || !$posts || !$user_uname) { die("<form action='acp.php?user=". $user_edit ."' method='POSTA'>Username: <input type='text' name='username' value='". $user_uname_c ."'><br>Posts: <input type='text' name='POST' value='". $posts_c ."'><br> Points: <input type='text' name='points' value='". $points_c ."'><br><input type='submit' value='Update user: ". $user_edit ."'></form><br><br>Make sure all fields are filled out!"); } else { //update everything mysql_query("UPDATE users SET points='$points' WHERE username='$user_edit'") or die(mysql_error()); mysql_query("UPDATE users SET posts='$posts' WHERE username='$user_edit'") or die(mysql_error()); mysql_query("UPDATE users SET username='$user_uname' WHERE username='$user_edit'") or die(mysql_error()); echo "User updated!"; } } } } else exit ?> Quote Link to comment https://forums.phpfreaks.com/topic/182588-why-doesnt-it-update/ Share on other sites More sharing options...
doddsey_65 Posted November 23, 2009 Share Posted November 23, 2009 Try: $sql =("UPDATE users SET points='$points' WHERE username='$user_edit'") or die(mysql_error()); $result = mysql_query($sql, $connect); Quote Link to comment https://forums.phpfreaks.com/topic/182588-why-doesnt-it-update/#findComment-963701 Share on other sites More sharing options...
3raser Posted November 23, 2009 Author Share Posted November 23, 2009 I don't think that that's my error. I need it to display that the user has been updated. And it's not, every time I fill out the information and click Update user, it just brings me right back to the form. It doesn't display: "User has been updated!" or anything like that. Quote Link to comment https://forums.phpfreaks.com/topic/182588-why-doesnt-it-update/#findComment-963704 Share on other sites More sharing options...
AE117 Posted November 23, 2009 Share Posted November 23, 2009 I don't think that that's my error. I need it to display that the user has been updated. And it's not, every time I fill out the information and click Update user, it just brings me right back to the form. It doesn't display: "User has been updated!" or anything like that. It doesnt look like it is getting to that part of the code since it is located in an else statement. Apparently the first statment is getting set as true which is not allowing the else statement to run. Quote Link to comment https://forums.phpfreaks.com/topic/182588-why-doesnt-it-update/#findComment-963710 Share on other sites More sharing options...
Alex Posted November 23, 2009 Share Posted November 23, 2009 You should be using isset. if(!isset($points, $posts, $user_uname)) Quote Link to comment https://forums.phpfreaks.com/topic/182588-why-doesnt-it-update/#findComment-963712 Share on other sites More sharing options...
3raser Posted November 23, 2009 Author Share Posted November 23, 2009 You should be using isset. if(!isset($points, $posts, $user_uname)) Doesn't help either. It just sends me to acp.php Quote Link to comment https://forums.phpfreaks.com/topic/182588-why-doesnt-it-update/#findComment-963713 Share on other sites More sharing options...
3raser Posted November 23, 2009 Author Share Posted November 23, 2009 Current code; <?php require "global_navigation.php"; ?> <?php //deleting //connect to database $connect = mysql_connect("$dbhost","$dbuser","$dbpassword") or die("Connection failed!"); mysql_select_db("$db") or die("Database fail!"); $delete_id = $_POST['iddelete']; if (!$delete_id) { } else { //write mysql_query("DELETE FROM posts WHERE id='$delete_id'") or die(mysql_error()); echo "<span style='color:green'>Successfully deleted post ID $delete_id.</span>"; } ?> <?php //user-editing //connect to database $connect = mysql_connect("$dbhost","$dbuser","$dbpassword") or die("Connection failed!"); mysql_select_db("$db") or die("Database fail!"); $name = $_SESSION['username']; //extract $extract = mysql_query("SELECT * FROM users WHERE username='$name'"); $numrows = mysql_num_rows($extract); while ($row = mysql_fetch_assoc($extract)) { $staffcheck = $row[staff]; } if ($staffcheck==2) { $user_edit = $_GET['user']; if (!$user_edit) { } else { //display data $get = mysql_query("SELECT * FROM users WHERE username='$user_edit'"); while ($row = mysql_fetch_assoc($get)) { // get data $points_c = $row['points']; $posts_c = $row['postcount']; $user_uname_c = $row['username']; $points = $_POST['points']; $posts = $_POST['posts']; $user_uname = $_POST['username']; if(!isset($points, $posts, $user_uname)) { die("<form action='acp.php?user=". $user_edit ."' method='POSTA'>Username: <input type='text' name='username' value='". $user_uname_c ."'><br>Posts: <input type='text' name='POST' value='". $posts_c ."'><br> Points: <input type='text' name='points' value='". $points_c ."'><br><input type='submit' value='Update user: ". $user_edit ."'></form><br><br>Make sure all fields are filled out!"); } else { //update everything mysql_query("UPDATE users SET points='$points' WHERE username='$user_edit'") or die(mysql_error()); mysql_query("UPDATE users SET posts='$posts' WHERE username='$user_edit'") or die(mysql_error()); mysql_query("UPDATE users SET username='$user_uname' WHERE username='$user_edit'") or die(mysql_error()); echo "User updated!"; } } } } else exit ?> <?php //promoting //connect to database $connect = mysql_connect("$dbhost","$dbuser","$dbpassword") or die("Connection failed!"); mysql_select_db("$db") or die("Database fail!"); $userw = $_POST['userw']; if (!$userw) { } else { //write mysql_query("UPDATE users SET staff='2' WHERE username='$userw'") or die(mysql_error()); echo "<span style='color:green'>Successfully promoted ". $userw ." to admin!</span>"; } ?> <?php //promoting //connect to database $connect = mysql_connect("$dbhost","$dbuser","$dbpassword") or die("Connection failed!"); mysql_select_db("$db") or die("Database fail!"); $userd = $_POST['userd']; if (!$userd) { } else { //write mysql_query("UPDATE users SET staff='0' WHERE username='$userd'") or die(mysql_error()); echo "<span style='color:green'>Successfully demoted ". $userd ." to a user!</span>"; } ?> <?php //banning //connect to database $connect = mysql_connect("$dbhost","$dbuser","$dbpassword") or die("Connection failed!"); mysql_select_db("$db") or die("Database fail!"); $ban = $_POST['ban_id']; if (!$ban) { } else { //extract $extract2 = mysql_query("SELECT * FROM users WHERE username='$ban'"); $numrows2 = mysql_num_rows($extract2); while ($row2 = mysql_fetch_assoc($extract2)) { $staffcheck2 = $row2[staff]; } if ($staffcheck2 ==1 || $staffcheck2 == 2) { echo "<span style='color:red'>You can't ban staff!</span>"; } else { //banning the account $banuser = mysql_query("UPDATE users SET banned='1' WHERE username='$ban'"); echo "<span style='color:green'>The user ".$ban." has successfully been banned!</span>"; } } ?> <?php //unbanning //connect to database $connect = mysql_connect("$dbhost","$dbuser","$dbpassword") or die("Connection failed!"); mysql_select_db("$db") or die("Database fail!"); $uban = $_POST['unban_id']; if (!$uban) { } else { //extract $extract3 = mysql_query("SELECT * FROM users WHERE username='$uban'"); $numrows3 = mysql_num_rows($extract3); while ($row3 = mysql_fetch_assoc($extract3)) { $staffcheck3 = $row3[staff]; } //unbanning the account mysql_query("UPDATE users SET banned='0' WHERE username='$uban'"); echo "<span style='color:green'>The user ".$uban." has successfully been unbanned!</span>"; } ?> <?php $name = $_SESSION['username']; //extract $extract = mysql_query("SELECT * FROM users WHERE username='$name'"); $numrows = mysql_num_rows($extract); while ($row = mysql_fetch_assoc($extract)) { $staffcheck = $row[staff]; } if ($staffcheck==2) { echo " <a href='view_reports.php'>View reports</a> <h3>Promote a user to ADMIN</h3> <form action='acp.php' method='POST'> Username: <input type='text' name='userw'> <input type='submit' value='Promote'> <hr> </form> <h3>Demote a user</h3> <form action='acp.php' method='POST'> Username: <input type='text' name='userd'> <input type='submit' value='Demote'> <hr> </form> <div class='box'> <h3>Delete a post</h3> <form action='acp.php' method='POST'> Message ID: <input type='text' name='iddelete'><input type='submit' value='Delete'><hr> </form> <h3>Ban Account</h3> <form action='acp.php' method='post'> Username: <input type='text' name='ban_id'> <input type='submit' value='Ban User'><hr></form> <h3>Unban Account</h3> <form action='acp.php' method='POST'> Username: <input type='text' name='unban_id'> <input type='submit' value='Unban User'><hr> </form> </div> "; } else { echo "<center><b><span style='color:red'>Only admins can enter this area!</span></b>"; } ?> <?php require("global_footer.php") ?> Quote Link to comment https://forums.phpfreaks.com/topic/182588-why-doesnt-it-update/#findComment-963714 Share on other sites More sharing options...
Alex Posted November 23, 2009 Share Posted November 23, 2009 Still, you should be using that instead. The reason why it's not working is because you have multiple flaws in your form. First off your method is POSTA, when it should be POST. Additionally your input which is supposed to be named posts is named POST. Quote Link to comment https://forums.phpfreaks.com/topic/182588-why-doesnt-it-update/#findComment-963716 Share on other sites More sharing options...
3raser Posted November 23, 2009 Author Share Posted November 23, 2009 Still, you should be using that instead. The reason why it's not working is because you have multiple flaws in your form. First off your method is POSTA, when it should be POST. Additionally your input which is supposed to be named posts is named POST. Ah, thank you for pointing that out. Simple mistakes. Quote Link to comment https://forums.phpfreaks.com/topic/182588-why-doesnt-it-update/#findComment-963718 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.