Dynadot .com transfer sale, only $10.12 with coupon code DYNA12, available while supplies last, ends October 31, 2026.

Deleting from Mysql, ids go the same.

Namecheap AuctionsNamecheap Auctions
Namecheap AuctionsNamecheap Auctions
Spacemail by SpaceshipSpacemail by Spaceship
Watch
Impact
11
When i click on Delete, it will delete the row from the mysql, but it will change all the ids to the same (as the one i deleted) and the row i deleted still shows up. I would need to refresh the page to change the ids back to their original ones and to have the row i deleted to dissapear. How can i do this without pressing the refresh button?

The code is:

Code:
    while ($row = mysql_fetch_array($rs))
    {
        $title = $row["title"];
        $url = $row["url"];
        $id = $row["id"];
        $category = $row["category"];
		$description = $row["description"];
		
if(isset($_GET["delete"])) {
	$id = $_GET["delete"];
	mysql_query("DELETE FROM tutorials WHERE id='$id' LIMIT 1");
}	
echo("<tr><td>$id</td><td>$title</td><td>$category</td><td>$description</td><td>Edit | <a href=\"tutorials.php?delete=$id\">Delete</a></td></tr>");
    }


Edit: i just fixed it so they dont all change to the same id (changed the $id in the isset to $tid) But how can i automaticaly refresh it?


Edit: i got it to work.
 
Last edited:
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
PHP:
    while ($row = mysql_fetch_array($rs))
    {
        $title = $row["title"];
        $url = $row["url"];
        $id = $row["id"];
        $category = $row["category"];
		$description = $row["description"];
		
if(isset($_GET["delete"])) {
	$sid = $_GET["delete"];
	mysql_query("DELETE FROM tutorials WHERE id='$sid' LIMIT 1");
}	
echo("<tr><td>$id</td><td>$title</td><td>$category</td><td>$description</td><td>Edit | <a href=\"tutorials.php?delete=$id\">Delete</a></td></tr>");
    }

Try that...

You overwrite $id and therefore remains constant. Try to change to $sid or some other variable not in use.

quote : Edit: i just fixed it so they dont all change to the same id (changed the $id in the isset to $tid) But how can i automaticaly refresh it? [[yea im lazy :D]]

use the header function.
header("Location: http://www.example.com/pageyouwanttogotto");
 
0
•••
I think this will be what your looking for: just changed it to make sure the id == the deleted row id. and continued the loop if it did so it doesn't print it out after deleting it. Hope that helps

PHP:
while ($row = mysql_fetch_array($rs))
{
    $title = $row["title"];
    $url = $row["url"];
    $id = $row["id"];
    $category = $row["category"];
	$description = $row["description"];
		
if(intval($_GET['delete']) == $id) {
	mysql_query("DELETE FROM tutorials WHERE id='$id' LIMIT 1");
	continue;
}
	
    echo("<tr><td>$id</td><td>$title</td><td>$category</td><td>$description</td><td>Edit | <a href=\"tutorials.php?delete=$id\">Delete</a></td></tr>");
}

EDIT: missed closing bracket in intval :P
 
0
•••
DomainEasy: flexible LTO options. Close more domain deals with financing.

We're social

Escrow.com
Spaceship
Escrowly
CryptoExchange.com
Domain Recover

NamePros updates

New in Parking: updated way to act on many domains or inquiries at once
Your domain list and inquiry list now have a bar above and below the list. Check the items you want, then choose an action in the bar...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back