Jump to content

simple code however problem


Danny620

Recommended Posts

Sorry this page is not available or has been accessed in error

 

An error occurred in script 'C:\xampp\htdocs\public_html\login\plugins\delete_product.php' on line 45: Undefined variable: id

Date/Time: 8-24-2010 00:50:10

 

Array

(

    [GLOBALS] => Array

*RECURSION*

    [_POST] => Array

        (

        )

 

    [_GET] => Array

        (

            [id] => 2

        )

 

 

      <?php # Script 9.2 - delete_product.php

// This page is for deleting a album.

require_once ('../includes/config.inc.php');

// Check for a valid product ID, through GET or POST:
if ( (isset($id)) && (is_numeric($id)) ) { // From editproducts.php
$id = $_GET['id'];
} elseif ( (isset($_POST['id'])) && (is_numeric($_POST['id'])) ) { // Form submission.
$id = $_POST['id'];
} else { 
echo '<p class="error">Sorry this page is not available or has been accessed in error</p>';
}
echo $id;
require_once(MYSQL); 

// Check if the form has been submitted:
if (isset($_POST['submitted'])) {

if ($_POST['sure'] == 'Yes') { // Delete the record.

	// Make the query:
	$q = "DELETE FROM products WHERE product_id='$id' LIMIT 1";		
	$r = @mysqli_query ($dbc, $q);
	if (mysqli_affected_rows($dbc) == 1) { // If it ran OK.

		// Print a message:
		echo '<p>The Product has been deleted.</p>';	

	} else { // If the query did not run OK.
		echo '<p class="error">The Product could not be deleted due to a system error.</p>'; // Public message.
		echo '<p>' . mysqli_error($dbc) . '<br />Query: ' . $q . '</p>'; // Debugging message.
	}

	 // Make the query:
	$q = "DELETE FROM photos WHERE product_id='$id'";		
	$r = @mysqli_query ($dbc, $q); 

} else { // No confirmation of deletion.
	echo '<p>The Product has NOT been deleted.</p>';	
}

} else { // Show the form.

// Retrieve the albums information:
$q = "SELECT name FROM products WHERE product_id='$id' Limit 1";
$r = @mysqli_query ($dbc, $q);

if (mysqli_num_rows($r) == 1) { // Valid user ID, show the form.

	// Get the user's information:
	$row = mysqli_fetch_array ($r, MYSQLI_NUM);

	$form = $_SERVER['PHP_SELF']; 

	// Create the form:
	echo '<form action="' . $form . '" method="post">
<h1>Delete ' . $row[0] . '?</h1>
<p>Are you sure you want to delete ' . $row[0] . '?<br />
<p><b>Warning if you delete this album all content inside of it will be losed!</b><br />
<input type="radio" name="sure" value="Yes" /> Yes 
<input type="radio" name="sure" value="No" checked="checked" /> No</p>
<p><input type="submit" name="submit" value="Submit" /></p>
<input type="hidden" name="submitted" value="TRUE" />
<input type="hidden" name="id" value="' . $id . '" />
</form>';

}
}


mysqli_close($dbc);

?>

Link to comment
https://forums.phpfreaks.com/topic/211562-simple-code-however-problem/
Share on other sites

It's pretty self-explanatory isn't it?

 

Your if statement at the start isn't setting $id to anything, so it's echoing that error message but you haven't used exit or die to stop the script, it just keeps executing which means when it tries to echo $id it can't because it hasn't been defined.

 

The first part of your if statement should be like this as well:

 

if ( (isset($_GET['id'])) && (is_numeric($_GET['id'])) ) {

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.