Dynadot โ€” .com Registration $8.99

Deleting from Mysql, ids go the same.

Spaceship 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
•••
Dynadot โ€” .com Registration $8.99Dynadot โ€” .com Registration $8.99
Unstoppable Domains
Domain Recover
DomainEasy โ€” Live Options
  • The sidebar remains visible by scrolling at a speed relative to the pageโ€™s height.
Back