Re: Mysql Row Deletion Fails
I corrected this:
mysqli_query($conn,"DELETE FROM users WHERE id='$val'");
to this:
mysqli_query($conn,"DELETE FROM users WHERE ids='$val'");
And this code is working:
Code:
<?php
/*
ERROR HANDLING
*/
declare(strict_types=1);
ini_set('display_errors', '1');
ini_set('display_startup_errors', '1');
error_reporting(E_ALL);
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
include 'config.php';
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Follow Users</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<form name="form" action="" method="post">
<table border=1 cellpadding=1 cellspacing=1>
<tr>
<th>Id</th>
<th>Username</th>
<th>Password</th>
<th>Email</th>
<th>Delete</th>
</tr>
<?php
$res=mysqli_query($conn,"SELECT ids, usernames, passwords, emails FROM users");
while($row=mysqli_fetch_array($res))
{
echo "<tr>";
echo "<td>"; echo $row["ids"]; ?> <input type="checkbox" name="num[]" class="other" value="<?php echo $row["ids"]; ?>" /> <?php echo "</td>";
echo "<td>"; echo $row["usernames"]; "</td>";
echo "<td>"; echo $row["passwords"]; "</td>";
echo "<td>"; echo $row["emails"]; "</td>";
echo "<td>"; echo "<input type='submit' name='submit' value='delete selected'>"; "</td>";
echo "</tr>";
}
?>
</table>
</form>
<?php
if(isset($_POST["submit"]))
{
$box=$_POST['num'];
while (list ($key,$val) = @each ($box))
{
mysqli_query($conn,"DELETE FROM users WHERE ids='$val'");
}
?>
<script type="text/javascript">
window.location.href=window.location.href;
</script>
<?php
}
?>
</body>
</html>
But, how come it's working since this is deprecated:
@each
And this also working:
Code:
<?php
/*
ERROR HANDLING
*/
declare(strict_types=1);
ini_set('display_errors', '1');
ini_set('display_startup_errors', '1');
error_reporting(E_ALL);
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
include 'config.php';
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Follow Users</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<table border=1 cellpadding=1 cellspacing=1>
<tr>
<th>Id</th>
<th>Username</th>
<th>Password</th>
<th>Email</th>
<th>Delete</th>
</tr>
<?php
$sql = "SELECT ids, usernames, passwords, emails FROM users";
$result = mysqli_query($conn,$sql);
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>".$row['ids']."</td>";
echo "<td>".$row['usernames']."</td>";
echo "<td>".$row['passwords']."</td>";
echo "<td>".$row['emails']."</td>";
echo "<td><a href=delete2a.php?ids=".$row['ids'].">Delete</a></td>";
}
?>
</table>
</body>
</html>
Also, why on the 1st code the concatenation is used while on the 2nd one not ?
Code:
echo "<td>"; echo $row["usernames"]; "</td>";
Code:
echo "<td>"; echo .$row["usernames"]; "</td>";
Do you suggest I use the concatenator or not ?
@anyone:
Any chance anyone can convert those 2 codes to use not deprecated stuffs so other beginners too can learn from your input ?
Thanks!
Re: Mysql Row Deletion Fails
It means you are testing, evaluating, or printing a variable that you have not yet assigned anything to. It means you either have a typo, or you need to check that the variable was initialized to something first. Check your logic paths, it may be set in one path but not in another.
Re: Mysql Row Deletion Fails
Quote:
Originally Posted by
Priya456
It means you are testing, evaluating, or printing a variable that you have not yet assigned anything to. It means you either have a typo, or you need to check that the variable was initialized to something first. Check your logic paths, it may be set in one path but not in another.
Thanks! :thumb:
But, you answered my 1st post and missed the 2nd.