Image

Image_kevin_mc_lean_ wrote in Imagephp

Set status script. Help please

I have the script which allows to register new users (field 'nick' in data base) and set their default status as "simpleuser" (field 'stat' in data base). And I want a page where all new users with status "simpleuser" will be listed one after another in table. And near each nick will be form where I could select a user's new status ('moderator' or 'administrator'). And after this table will be a button for subnision which updated database with new values.

I've wtitten code. But it doesn't work :(

So, it consists of two files [B]sending.php[/B] and [B]user_submit.php[/B].

sending.php

<?php

include('connection.php');

$query = "SELECT id, nick, email FROM test WHERE stat = 'newuser'";
$result = mysql_query($query) or die("ERROR: $query.".mysql_error());

// if records are present
if (mysql_num_rows($result) > 0) {
    $row = mysql_fetch_assoc($result);
    $id = $row->id;

    echo "<table><tr>"; 
        echo "<td>".$row[nick]."</td>";
        echo "<td><a href=mailto:$row[email]>".$row[email]."</a></td>";  
        echo "</tr><table>";
    echo "<form method = post action = user_submit.php>";
   
        echo "<select name=newstat size=1>
    <option value=administrator>administrator</option>
    <option value=moderator>moderator</option>
</select>
    echo "<input type = hidden name = id value = '$id'>";
    echo "<input type = submit name = submit value = Submit>";
    echo "</form>";
 }

else {
    echo 'No new users';
}

// close connection
mysql_close($connection);

?>

Problem here:
There is only one user shown in the table, but in the db there're many of them. Why does it show only one?

user_submit.php

<?php

if (isset($_POST['submit'])) {

    include('connection.php');
   
    $result = mysql_query("UPDATE test SET stat = '{$_POST['newstat']}'  WHERE id = '{$_POST['id']}'");
    // close connection
    mysql_close($connection);


    // print success message   
    echo 'Done';
}
else {
    die('ERROR: Data not correctly submitted');
}

?>

The problem here is:
It doesn't set new status to users. But I'm not sure that mistake which causes this problem in user_submit.php, it might be in sending.php

Help me please.