Folks,
Here is a php code that lists all the rows and columns in your mysql tbl for you to select the rows (via check boxes) you want to delete and then delete them by clicking the appropriate "delete" buttons. Problem is, when I click any of the "delete" buttons, I get error flicking for a sec that there is an undefined variable $num. Not sure where to define it and how.
Confesssion :D
I actually play-paused 2 youtube videos and copy typed the code you see. That is one way I learn and gain a little work experience. Was not aware that the "each" function was deprecated until another told me.
Even though, I checked the foreach loop tutorial, here I am at a loss how to make use of it. Feeling flabbergasted in my failure! -
<?php
-
session_start();
-
require "conn.php";
-
require "site_details.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 * 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 id='$val'");
-
}
-
?>
-
<script type="text/javascript">
-
window.location.href=window.location.href;
-
</script>
-
<?php
-
}
-
?>
-
-
</body>
-
</html>
-
Here's another one. But, this one does not have the DELETE BUTTON. DELETE LINK instead. Same problem I'm facing on this one too. Not deleting anything. -
<?php
-
session_start();
-
require "conn.php";
-
require "site_details.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 * 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?id=".$row['ids'].">Delete</a></td>";
-
}
-
-
?>
-
</table>
-
</body>
-
</html>
-
-
Can some good Samaritan fix the 2 codes so we beginners can learn from your examples ? :)
I've come this far on these 2. Don't want to quit at the end.
Cheers!
1 1915
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: -
-
<?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: -
<?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 ? -
echo "<td>"; echo $row["usernames"]; "</td>";
-
-
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!
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Fraser Hanson |
last post by:
Hello,
I have a table which has a foreign key relationship with itself. I
want and expect my updates to cascade (deletes definitely cascade as
expected) but instead I just get error 1217:...
|
by: rb |
last post by:
I have two XP computers, with the same version of MySQL on each. I
have the same database structure and data on each. Each computer has
the same user name, and each MySQL database has the same...
|
by: Vic |
last post by:
Hi all,
When I test the Delete multi table function in MySQL,
DELETE table_name ...]
FROM table-references
I accidentally delete all data in one table. All data in that table
are gone...
|
by: Dan Greenblatt |
last post by:
I am writing some software that, among other things, needs to track
the state of database tables. This includes occasionally checking the
table to see what records or added, modified, or deleted....
|
by: Martin_Hurst |
last post by:
It would appear that MySQL is making great strides into the commercial and
even the enterprise arena.
I am not seeing the same news coverage being said about Postgresql.
I believe Postgresql has...
|
by: John Salerno |
last post by:
My web server told me it isn't, which is why they are sticking with
MySQL 4.0 for now, but I'm obsessed with using the latest versions, so I
just want to be sure. According to the mysqldb download...
|
by: thomasjbs |
last post by:
I'm trying to migrate a Wiki database to another server. I have zero
problems backing up the database using multiple methods. But the Mysql
restore fails with:
ERROR 1064 at line 52: You have...
|
by: David |
last post by:
Hi,
I have a MySQL database linked to an MS Access front-end.
I have an app which works fine with the local copy of the Access DB,
but when run with the linked tables for MySQL, it fails.
...
|
by: rizwan6feb |
last post by:
I have to develop a database application in vb.net 2005 with the following rules
1. The application connects with an online mysql database (i.e database resides on a remote machine)
2. The...
|
by: Atli |
last post by:
What to discuss:
What is a "MySQL resource".
What causes the error.
How to fix it.
Common Newbie Pitfalls
This article is the second installment in a series of (hopefully) many, following...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
| |