Hi there, i basically want a confirmation box to appear when a button is clicked, and ask the user whether they are sure if they want to delete a row from the database.

However, with the code i constructed now, whether ok or canel is clicked, the row is deleted anyway, If you can have a look over my code below and see why this is happening i will very much appreciate it thank you.


<link rel='stylesheet' href='layoutcms.css'>


<script language='JavaScript'>
function myFunction()
var x;
var r=confirm("Press a button!");
if (r==true)


<div id="header">
<h1><img src="laz_logocms.png"
width="380" height="60" alt="Laz Electric Products" border="0" />

<div class='navbar'>
<div class='button'><a href='add_product.php'>Add Product</a></div>
<div class='button'><a href='edit_product.php'>Edit Product</a></div>
<div class='button'><a href='delete_product.php'>Delete Product</a></div>
<div class='button'><a href='index.php'>Front End</a></div>


<div id="page-container">

<div id="content">
<div class="padding">
<h2>Please select one of the options below by clicking a button.</h2>

if (isset($_REQUEST['id'])) {
$id = $_REQUEST['id'];

// Connect to server and select database

require_once "config.php";
$dbhandle = mysql_connect($hostname, $username, $password);

if (!$dbhandle) die("unable to connect to mysql: " . mysql_error());

or die ("unable to connect to databse: " . mysql_error());

// Get values from form

if (isset($_POST['delete']) && isset($_POST['id']))

// Delete data from mysql

$id = get_post('id');

$query = "DELETE FROM products WHERE product_id = '$id'";

// if not successfully deleted data from database, displays message "delete failed".

if (!mysql_query($query, $dbhandle))
echo "delete failed: $query<br />" .
mysql_error() . "<br /><br />";

// Selects all colums rows from table and displays results

$query2 = "SELECT * FROM products";
$result = mysql_query($query2, $dbhandle);

//if not successful in selected data, display "database access failed"

if (!$result) die ("Database access failed: " . mysql_error());
$rows = mysql_num_rows($result);

//displays all records of tables, rather then just first one, which holds "product_id" 2

for ($j = '0' ; $j < $rows ; ++$j)

//returns the rows from table "laptop_products"

$row = mysql_fetch_row($result);

// data that needs to be displayed through above, function

echo <<<_END
product_id: $row[0]
product_name: $row[1]
weight: $row[2]
quantity: $row[3]
price: $row[4]
description: $row[5]
image: $row[6]
url: $row[7]
category: $row[8]

<form action="delete_product.php" method="post">
<input type="hidden" name="delete" value="yes" />
<input type="hidden" name="id" value="$row[0]" />
<input type="submit" onclick="myFunction()" value="DELETE RECORD" /></form>