Jump to content

Deleting multiple rows... ???


mikepuerto

Recommended Posts

Can anyone give me an idea as to why this does not work? I dont get any errors and it seems to run fine but does not delete the rows...

[code]
$file = $_GET['file'];
$lines = file($file);

foreach ($lines as $line_num => $line) {
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to the database');
mysql_select_db($dbname);
$query = "DELETE FROM largo1 WHERE id='$line'";
$result = mysql_query($query);
echo "$line deleted<br>";
}
mysql_close($conn);
[/code]
Link to comment
https://forums.phpfreaks.com/topic/21569-deleting-multiple-rows/
Share on other sites

The id column contains an auto_increment id. Each line of the file contains an ID that exists in the table. Therefore $line is the ID that I'm trying to delete. Not thinking about it very much i changed id="$line_num" resulting in the deletion of a a bunch of rows that i did not want to delete.

I have figured out that the script works. but it does not actually loop. It only deletes one.
Link to comment
https://forums.phpfreaks.com/topic/21569-deleting-multiple-rows/#findComment-96311
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.