Jump to content

Why doesn't it update?


3raser

Recommended Posts

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
?>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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") ?>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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. :P

Link to comment
Share on other sites

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.