473,500 Members | 1,943 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Deleting row in mysql database using php script

2 New Member
Hi everybody,

I need your help.

I want to view my sql database and its work very well which is display in my web browser
but once I want to press button yes, its not working, I check the database the specified row was nit deleted

Here I put my script for both.
[php]
<?php #script view_users.php pg 279


include 'index1.php';

//This script retrieves all the records from the register table.

//This new version links to edit and delete pages.

//Page header.
echo '<h1 id="mainhead">Registered Projects</h1>';

//cONNECT TO THE DATABASE.
require_once 'Connect/mysql_connect.php';

//Make the query.

$query = "SELECT serial, date, department, user_id, email, project, description FROM register";
//ORDER BY serial ASC";

//Run the query
$result = mysql_query ($query);
$num = mysql_num_rows($result);

if ($num > 0) { //If it ran OK, display the records.

echo "<p>There are currently $num registered users.</p>\n";

//Table header.

echo '<table align-"center" cellspacing="15" cellpadding-"5">
<tr>

<td align="left"><b>Serial</b></td>
<td align="left"><b>Date</b></td>
<td align="left"><b>Department</b></td>
<td align="left"><b>User</b></td>
<td align="left"><b>Email</b></td>
<td align="left"><b>Project</b></td>
<td align="left"><b>Description</b></td>
<td align="left"><b>Edit</b></td>
<td align="left"><b>Delete</b></td>
</tr>
';

//Fetch and print all the records.
$bg = '#eeeeee'; //set the background color.

while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
// echo '<tr>
$bg = ($bg=='#eeeeee' ? '#ffffff' : '#eeeeee'); //switch the background color.

echo '<tr bgcolor="' . $bg . '">

<td align="left">' . $row['serial'].'</td>
<td align="left">' . $row['date'].'</td>
<td align="left">' . $row['department'].'</td>
<td align="left">' . $row['user_id'].'</td>
<td align="left">' . $row['email'].'</td>
<td align="left">' . $row['project'].'</td>
<td align="left">' . $row['description'].'</td>
<td align="left"><a href="edit_user.php?serial_num=' . $row['serial'] . '">Edit</a></td>
<td align="left"><a href="delete_user.php?serial_num=' . $row['serial'] . '">Delete</a></td>
</tr>

';
}

echo '</table>';

mysql_free_result ($result); //Free up the resources.

} else { //If did not run OK.

echo '<p class="error">There are currently no registered projects.</p>';
}

mysql_close(); //Close the database connection.


?>


and below for deleting the project specified.


<?php #delete_user.php pg 283

//This page deletes a user.
//This page is accessed through view_users.php

//Check for a valid user serial number ID, through GET or POST.

if ( (isset($_GET['serial_num'])) && (is_numeric
($_GET['serial_num'])) ) { //acessed through view_users.php

$serial_num = $_GET['serial_num'];

} elseif ( (isset($_POST['serial_num']) ) &&

(is_numeric($_POST['serial_num'])) ) { //form has been submitted.

$serial_num = $_POST['serial_num'];

} 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>';
}

require_once 'Connect/mysql_connect.php'; //connect to the database.

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

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


//Make the query
$query = "DELETE FROM register WHERE serial=$serial_num";
$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
project</h1>

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

} else { //If the query did not run OK.

echo '<h1 id="mainhead">System
Error</h1>

<p class="error">The project could
not be deleted due to a system
error.</p>'; //public message
echo '<p>' . mysql_error() .
'<br /><br />Query: '. $query .
'</p>'; //debugging message.
}

} else { //wasn't not sure about deleting the project.

echo '<h1 id="mainhead">Delete a
project</h1>
<p>The project has NOT been deleted.
</p><p><br /></p>';

}


} else { // Show the form

//Retrieve the user's information.

$query = "SELECT project FROM register WHERE serial=$serial_num";

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


if (mysql_num_rows($result) == 1) { //valid serial number, show the form.

//Get the serial number information.

$row = mysql_fetch_array ($result, MYSQL_NUM);


//Create the form.

echo '<h2>Delete the project</h2>

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


} else { //Not a valid serial number.

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.

?>[/php]
Dec 8 '06 #1
2 4385
Niheel
2,456 Recognized Expert Moderator Top Contributor
wrong forum
moved to php
also added code tags
Dec 8 '06 #2
ronverdonk
4,258 Recognized Expert Specialist
Your form posts value "Submit" name "submit". [php]<input type="submit" name="submit" value="Submit" /></p>[/php]
Your form handler checks "submitted".[php]if (isset($_POST['submitted'])) {
[/php]

Ronald :cool:
Dec 8 '06 #3

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

Similar topics

3
15448
by: James | last post by:
HI, I'm looking for a script that will allow users/admins to have a one click backup solution for a MYSQL Database.. 'BACK DATABASE' button, click and its done... The a restore option, that...
4
4406
by: Neil | last post by:
Hi, I hope this question isn't too far off topic....I'm almost at my wits end trying to figure this out. I have a Mysql database and I wish to automate the backup of the database because I...
4
11475
by: MLH | last post by:
I am having failures processing the following command and I wonder if you can tell me what I must do in order to have success. When I try to run source mysql_dump.sql.txt ==> it is a problem...
4
8399
by: Ian Davies | last post by:
Hello all The following code allows me to connect to a local MySQL database on my pc from a VB6 project. **************************************************************************** ** Dim...
14
6068
by: mistral | last post by:
Need php script to create mySQL database programmatically; since hosting configuration may not allow create database from script, script also need eliminate/rewrite all restrictions in appropriate...
14
2875
by: Ben | last post by:
I don't know whether anyone can help, but I have an odd problem. I have a PSP (Spyce) script that makes many calls to populate a database. They all work without any problem except for one...
6
1786
by: keeps21 | last post by:
I'm having a bit of trouble creating a page to delete a story from the content table in my database. I have checked my DELETE query directly in phpmyadmin and it is working fine. I am echoing...
4
3884
by: Jerim | last post by:
I have a script on one server, trying to access the MySQL database on another server. The server with the script is on an outside network, hosted with another company. The MySQL server is here in...
39
5823
by: alex | last post by:
I've converted a latin1 database I have to utf8. The process has been: # mysqldump -u root -p --default-character-set=latin1 -c --insert-ignore --skip-set-charset mydb mydb.sql # iconv -f...
0
7136
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
7018
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
7232
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6906
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
7397
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
5490
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,...
1
4923
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...
0
3110
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
672
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.