Hi all,
I have problems in my script in sending data with POST method
By pressing Submit button nothing happends.
Here are my scripts.
/*********************************************************
Code for delete_users_form.php
It loads users from database and put to each row a checkbox
User should check some boxes for deleting users accounts
***********************************************************/
<?php
session_start();
/
Check if user is logged in and if he has admin rights
$SESSION['valid_user'] and $SESSION['user_type'] == admin are filled on logging page
/
if ((isset($SESSION['valid_user'])) && ($SESSION['user_type'] == admin))
{
//Connecting to database
$db_conn = new mysqli('localhost', 'root', '', 'ep');
if (mysqli_connect_errno()):
echo 'Cant connect to database.'.mysqli_connect_error();
exit();
Endif;
//Selecting all users from database
$query = "select username, type from users";
$result = $db_conn->query($query);
$num_results = $result->num_rows;
//Creating form I dont know if here is an error
?>
<html>
<head>
<title>Zmazanie uzivatela </title>
</head>
<body>
<form action="delete_users.php" method="post">
<table border=0 cellpadding=4>
<?php
echo '<tr> <td></td><td>Username</td><td>Rights</td><td>Delete?</td></tr>';
if ($result->num_rows > 0):
for ($i=0; $i < $result->num_rows; $i++)
{
$row=$result->fetch_assoc();
$name=$row['username'];
echo '<tr><td><strong>'.($i+1).'. </strong></td>';
echo '<td>'.htmlspecialchars(stripslashes($row['username'])).'</td>';
echo '<td>'.stripslashes($row['type']).'</td>';
echo "<td><input type='checkbox' name='chk_del_usr[]' value='$name'></td></tr>";
}
?>
</table>
</form>
</body>
</html>
<?php
Endif;
$result->free();
$db_conn->close();
//Submit
echo "<input type='submit' value='Delete'>";
//Another option for submit as a link
//echo "<a href'#' onClick='act_users.submit();'>Zmazat uzivatela</a>";
echo'<br />';
echo '<a href="authmain.php">Main page.</a><br />';
}
else
{
echo'You are not logged in or you have insuficient rights!';
echo'<br />';
echo '<a href="authmain.php">Main page.</a><br />';
}
?>
/*************************************
delete_users.php
Main script
**************************************/
<?php
session_start();
/
Check if user is logged in and if he has admin rights
$SESSION['valid_user'] and $SESSION['user_type'] == admin are filled on logging page
/
if ((isset($SESSION['valid_user'])) && ($SESSION['user_type'] == admin))
{
//short variables
$chk_del_usr=$POST['chk_del_usr'];
if (filled_out($POST))
{
if (count($chk_del_usr) >0)
{
//Connecting to database
$db_conn = new mysqli('localhost', 'root', '', 'ep');
if (mysqli_connect_errno()):
echo 'Cant connect to database.'.mysqli_connect_error();
exit();
Endif;
foreach($chk_del_usr as $name)
{
//Deleting selected users
$query = "delete * from users where username='$name'";
$result = $db_conn->query($query);
if ($result)
{
echo 'Deleted users:'.$name.'!!!'; //just for info
}
else
{
echo 'Error!!! User '.$name.' cant be deleted!!!<br />'; //some error
}
}
echo '<a href="authmain.php">Main page.</a><br />';
}
else
{
echo'There arent users for delete!'; //if array $chk_del_usr is empty
echo '<a href="authmain.php">Main page.</a><br />';
}
}
else
{
echo'You havent choose any user for delete!'; //if admin havent checked any user account for deleting
echo '<a href="authmain.php">Main page.</a><br />';
}
}
else
{
echo'You are not logged in or you have insuficient rights!';
echo'<br />';
echo '<a href="authmain.php">Main page.</a><br />';
}
?>