Form doesn't update

Somehow when I click submit, it echoes the message, but it doesn’t update it.


<?php
if (isset($_POST['Submit'])) {
		if ((!empty($_POST['active']))) {
				$_POST['active'] = round($_POST['active']);
				mysql_query("UPDATE users SET active='" . $npercentage . "' WHERE id='1'") or die("MYSQL is indeed gay: ".mysql_error());
		}
				echo 'Status updated'; 
	} //If Submit

?>
		<tr>
    <td><strong>Activate/Suspend :</strong></td>
    <td>
<input size="250" class="booter" value="<? echo $active; ?>" name="active" type="text" id="active">Fill in "activated" to active, other text for suspend.
</td>
  </tr>
<tr>
<td>
</td>
<td>
<input type="submit" class="booter" name="Submit" value="Update">
</td>
</form>

Perhaps you meant


				$npercentage = round($_POST['active']);
				mysql_query("UPDATE users SET active='" . $npercentage . 

I copied a code from another form which was in percentages, I made a text box where it says by default activated, but if you put something else and submit it changes the row “active” in mysql, and another script checks if it says something else then activated then it will not make him loginable and displays the message u wrote.

So I just need to make it change the row active when I submit, but it echoes the successfull message but doesn’t update anything.

still need help!

Hello everyone on the forum, I’m a new member from Croatia!

<?php
if (isset($_POST['Submit'])) {
		$percentage = round($_POST['active']);
		if ((!empty($_POST['active']))) {
				
				mysql_query("UPDATE users SET active = '$percentage' WHERE id='1'") or die("MYSQL is indeed gay: ".mysql_error());
		}
				echo 'Status updated'; 
	} //If Submit

?>

Try that, lemme know any errors or if it works.

Wrong section to post vili?

Its not ment to do percantage…
I have in mysql a forum that says activated when its activated,

then i got a option to edit users, so i can change activated to something else.

Could you post the actual code you’re having problems with? Or if that is it, where is $npercentage being set?

Really dont understand what you are trying to do.

You have a form with a feild caled ‘active’

What do you want this value to do? Update users where id = 1 and set active to the value specified?

Look, I had already a form where you could update percentage of useres right.

Now I wanted to make another one but for activated, but that didn’t work out well.

Its like a cms where you can edit users percantage use, if account is activated or not, change accounts password etc,

just couldn’t make one for activated.

I copied the percantage form tried to make one for activated.

mysql_query("UPDATE users SET active='" . $npercentage . "' WHERE id='1'") or die("MYSQL is indeed gay: ".mysql_error());

If you look at your code, you’re trying to set the ‘active’ field to equal $npercentage. Where are you setting anything to the variable $npercentage?

I think I’m setting it via $percentage = round($_POST[‘active’]);

Also, I don’t want the text I’m going to set in percantages or what ever.

That’s not what’s in your code… That’s what Ben and I posted…
Try actually testing what Ben posted :slight_smile:



<?php
if (isset($_POST['Submit'])) {
        $active_v = ($_POST['active']);
        if ((!empty($_POST['active']))) {
                
                mysql_query("UPDATE users SET active = '$active_v' WHERE id='1'") or die("MYSQL is indeed gay: ".mysql_error());
        }
                echo 'Status updated'; 
    } //If Submit

?>


That will update the mysql record for user 1 and set active to whatever you type in the form.

Oh if this isn’t a number then let’s not forget to escape that!



<?php
if (isset($_POST['Submit'])) {
        $active_v = mysql_real_escape_string($_POST['active']);
        if ((!empty($_POST['active']))) {
                
                mysql_query("UPDATE users SET active = '$active_v' WHERE id='1'") or die("MYSQL is indeed gay: ".mysql_error());
        }
                echo 'Status updated'; 
    } //If Submit

?>


Would I need to change anything in html part? I think I would?

No nothing.

Nope doesn’t update it…

Echo the query and run it directly in MySQL to see what is going on easily.

If the condition fails than it has something to with either the value not existing in the post or perhaps it is a 0. If the value is a 0 than empty() will be true, hence the condition will fail.

There are a few things to try.