Problem in PHPmyadmin for BYO DB Driven w/s in php/mysql

Im having the same sort of problem, but im using PHPmyadmin! If it helps i am trying to create the CMS on page 206 in Sitepoint book BYO database driven website in php & mysql.

When i hit the delete button its supposed to delete an author and all related data in other tables. It deletes the author but fails to remove the primary key id in phpmyadmin? So im left with blank results (bullit point) on the page with a edit and delete next to it.

This is my code (sorry for length)

[B]if (isset($_POST[‘action’]) and $_POST[‘action’] == ‘Delete’)
{
include $_SERVER[‘DOCUMENT_ROOT’] . ‘/includes/dbcon.inc.php’;

		$id = mysqli_real_escape_string($link, $_POST['id']);
		$sql = "SELECT id FROM soulfire_joke WHERE authorid='$id'";

		$result =mysqli_query($link, $sql);

		if (!result)
			{
				$error = 'Error Getting list off jokes to delete!';
				include 'error.html.php';
				exit();
			}



		while ($row = mysqli_fetch_array($result))
			{
				$jokeId = $row[0];

				$sql ="DELETE FROM soulfire_jokecategory
					   WHERE jokeid='$jokeId'";

					   if(!mysqli_query($link, $sql))
					   	{
					   		$error = 'Error Deleting category enteries for joke!';
					   		include 'error.html.php';
					   		exit();
					   	}
			 }

			$sql = "DELETE FROM soulfire_joke WHERE authorid = '$id'";
			if(!mysqli_query($link, $sql))
				{
					$error = 'Error deleting jokes for author!';
					include 'error.html.php';
					exit();
				}

			$sql = "DELETE * FROM soulfire_author WHERE id='$id'";
			if(!mysqli_query($link, $sql))
				{
					$error = 'Error deleting the author';
					include 'error.html.php';
					exit();
				}

				header('Location: .');
				exit();
		}

[/B]

Your problem may be due to the wildcard character in your SQL statement:

DELETE * FROM soulfire_author WHERE id='$id'

That should be:

DELETE FROM soulfire_author WHERE id='$id'

Note that if the ID is an integer, quotes are not recommended. I’d recommend casting it to an integer then leaving it unquoted in the query.

Whey got it to work now! I can edit and Delete authors but i am having trouble with the header(‘Location: URL’) malarky!

when i do the editing/deleting and press the approiate button it comes back with Cannot modify header information - headers already sent by…

But when i manually refresh the page the items appear or are removed from the list? Where do i want to point my Header URL to? Sorry for stupid questions im new to php/mysql, i have a java background lol

That error is caused by outputting anything before a header - that could be HTML, text, whitespace etc.

What you need to do is make sure nothing at all is output before the redirection header - that means doing all of the processing before anything else.

What if its an array thats tripping up the ‘output’ thats needed to run first in order to Select and display the information which gets edited/deleted?