473,396 Members | 2,033 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Problem with deleting records from DB

Odisey
14
I am not sure if this is a MySQL syntax error or a DB issue yet. I am getting the error from the code:

Page Error!
This page has been accessed in error.

The GET is populated in the browser address window with a valid user ID, yet I get the error. I've studied this script - it should work.

Any ideas?

===================================
[PHP]
<?php
//This page delets a user
//This page is accessed through view_users.php

$page_title = 'Delete a user';
include ('./includes/header.html');

//Check for a valid user ID through GET or POST

if ( (isset($_GET['id'])) && (is_numeric($_GET['id'])) ) { //Accessed through view_users.php
$id = $_GET['id'];

} elseif ( (isset($_POST['id'])) &&
(is_numeric($_POST['id'])) ) { //Form has been submitted

$id = $_POST['id'];

} else { //No valid ID - kill the script

echo '<h1 id="mainhead">Page error.</h1>
<p class="error">This page has been accessed in error.</p><p><br /><br /></p>';


include ('./includes/footer.html');
exit();

}

require_once ('mysql_connect2.php'); //Connect to DB

// Check if the form has been submitted

if (isset($_POST['submitted'])) {

if ($_POST['sure'] == 'Yes') { //Delete them

//Make the enquiry
$query = "DELETE FROM users WHERE user_id=$id";

$result = @mysql_query ($query); //Run the query

if (mysql_affected_rows() == 1) { //If it ran OK


//Print a message
echo '<h1 id="mainhead">Delete a User</h1>
<p>The user has been deleted.</p><p><br /><br /></p>';

} else { //If the query did not run

echo '<h1 id="mainhead">System error</h1>
<p class="error"> The user could not be deleted due to a system error.</p>'; //Message
echo '<p>' . mysql_error() . '<br /><br />Query: ' . $query . '</p>'; //Debugging message

}

} else { // Was not sure about deleting the user

echo '<h1 id="mainhead"> Delete a User </h1>

<p> The user has NOT been deleted. </p><p><br /><br /></p>';

}

} else { //Show the form


//Retrieve the user's information

$query = "SELECT CONCAT(last_name, ', ', first_name) FROM users WHERE user_id=$id";

$result = @mysql_query ($query); //Run the query

if (mysql_num_rows($result) == 1) { // Valid user ID - show the form

// Get the users information

$row = mysql_fetch_array ($result, MYSQL_NUM);

//Create the form

echo '<h2> Delete a User </h2>

<form action="delete_user.php" method="post">
<h3>Name: ' . $row[0] . '</h3>
<p>Are you sure you want to delete this user?<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>';

} else { //Not a valid ID

echo '<h1 id="mainhead">Page Error</h1>
<p class="error">This page has been accessed in error.</p><p><br /><br /></p>';

}


} //End of the main submit conditional

mysql_close(); //Close the database connection

include ('./includes/footer.html');

?>
[/PHP]
===============================================
May 14 '07 #1
3 1353
Odisey
14
I found it!

The = sign in the id input tag......

Sorry to bother...

Odisey
May 14 '07 #2
Atli
5,058 Expert 4TB
I'm glad you found your answer.

Just a thought, I usually put a limit clause on all DELETE and UPDATE statements to minimize the damage if something were to go wrong.
May 14 '07 #3
pbmods
5,821 Expert 4TB
If where the variable came from isn't important (as appears to be the case in your script), you can also just use $_REQUEST (starting with PHP v4.1).

Expand|Select|Wrap|Line Numbers
  1. $id = $_REQUEST['id'];
  2. // Or better yet...
  3. $id = addslashes($_REQUEST['id']);
  4.  
http://www.php.net/manual/en/reserved.variables.php (most of the way down the page)
May 15 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Mark | last post by:
This question refers to a main form with a continuous form subform. After an error occurs after entering several records in the subform, how can I delete all the data in the main form and all the...
1
by: KC | last post by:
Hello, I am using Access 2002. WinXP, Template from MS called Orders Mgmt DB. I have tweaked this DB to work for our small co. It has worked pretty well up until I made the mistake of deleting...
13
by: Bob Darlington | last post by:
I have a repair and backup database routine which runs when a user closes down my application. It works fine in my development machine, but breaks on a client's at the following line: If...
4
by: JN | last post by:
Hi all, I have some pages where I need to delete/update database records. Everything is fine until I hit the refresh button on the browser (IE). This will cause the pages to repeat the last...
11
by: shriil | last post by:
Hi I have this database that calculates and stores the incentive amount earned by employees of a particular department. Each record is entered by entering the Date, Shift (morn, eve, or night)...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.