What'd I mess up on? (Delete row MySQL) - Webmaster Forums - Webmaster forum for HTML, PHP, ASP, CSS and more
Webmaster Forums - Webmaster forum for HTML, PHP, ASP, CSS and more
Go Back   Webmaster Forums - Webmaster forum for HTML, PHP, ASP, CSS and more > Webmaster Tech > Programming > PHP Development

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 11-05-2007, 10:23 AM   #1 (permalink)
Junior Member
 
Join Date: May 2006
Posts: 2
Default What'd I mess up on? (Delete row MySQL)

I'm trying to develop a script that would allow deletion of a specific row, and it's working semi-okay.

Only problem is, it's not deleting. Figures, eh?

PHP Code:
<?php
connection info here

mysql_connect
($DBhost,$DBuser,$DBpass) or die("There was a connection error and I am unable to continue");

@
mysql_select_db("$DBName") or die("I was not able to connect to the database");


if(
$_GET['delete']){
$item $_GET['delete'];
mysql_query("DELETE FROM $table WHERE pilot_id='$id'") or die(mysql_error());
}

// Get all the data from the "example" table
$result mysql_query("SELECT * FROM $table WHERE status='P5' ORDER BY pilot_id")
or die(
mysql_error());

echo 
"<table width='100%' border='0'>";
echo 
"<tr> <td class='heading' width='15'><span style='font-size:8px';>Edit</span></td> <td class='heading' width='25'><span style='font-size:8px';>Delete</span></td> <td class='heading' width='25'>ID</td> <td class='heading' width='200'>Name</td> <td class='heading' width='100'>Hub</td> <td class='heading'>Email</td>";
// keeps getting the next row until there are no more to get
while($row mysql_fetch_array$result )) {
// Print out the contents of each row into a table
echo "<tr><td style='font-size:8px'>";
echo 
"Edit";
echo 
"</td><td style='font-size:8px'>";
echo 
'<a href="?delete='.$row['pilot_id'].'">Delete</a>';
echo 
"</td><td>";
echo 
$row['pilot_id'];
echo 
"</td><td>";
echo 
$row['name'];
echo 
"</td><td>";
echo 
$row['hub'];
echo 
"</td><td>";
echo 
$row['email'];
echo 
"</td><td>";
}

echo 
"</table>";
?>
I'm sure it's a simple fix, but I just can't see where I went wrong. Any advice?
zTagged is offline   Reply With Quote
Sponsored Links
Old 11-06-2007, 05:18 AM   #2 (permalink)
Junior Member
 
Join Date: Nov 2007
Posts: 2
Default Re: What'd I mess up on? (Delete row MySQL)

I guess at this line the problem
Code:
if($_GET['delete']){
$item = $_GET['delete'];
mysql_query("DELETE FROM $table WHERE pilot_id='$id'") or die(mysql_error());
}
You may try the following code
Code:
if($_GET['delete']){
$item = $_GET['delete'];
mysql_query("DELETE FROM $table WHERE pilot_id='$item'") or die(mysql_error());
}
edpudol is offline   Reply With Quote
Old 11-17-2007, 01:12 PM   #3 (permalink)
Junior Member
 
Join Date: Nov 2007
Posts: 8
Default Re: What'd I mess up on? (Delete row MySQL)

Quote:
Originally Posted by edpudol
I guess at this line the problem
Code:
if($_GET['delete']){
$item = $_GET['delete'];
mysql_query("DELETE FROM $table WHERE pilot_id='$id'") or die(mysql_error());
}
You may try the following code
Code:
if($_GET['delete']){
$item = $_GET['delete'];
mysql_query("DELETE FROM $table WHERE pilot_id='$item'") or die(mysql_error());
}
I'd like to point out that doing things like this:
Code:
mysql_query("DELETE FROM $table WHERE pilot_id='$item'") or die(mysql_error());
Is a bad habit to get into. You should be very careful when feeding variables into SQL strings. This can lead to whats called an SQL Injection attack, if the variable came from user entered content, such as on a form post or a GET var.

The better practice to get yourself into the habit of:

Code:
$item = mysql_escape_string($_GET['delete']); 
mysql_query("DELETE FROM $table WHERE pilot_id='$item'") or die(mysql_error());
If I were a hacker on your site, I could easily delete all the rows in your table by adding some extra content on the URL (unless you escape the incoming data)

See the PHP manual:

PHP: mysql_escape_string - Manual

Regards,
Mark
websiterepairguys is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Sponsors

» Links

» Affiliates
Web Hosting
Online Backup Reviews
Marketing Find
Merchant Select
SiteMap Builder
Host Compare

» Links

» Sports Network
Paintball Forum
Football Forum
Hockey Forum
Golf Forum
Boxing Forum
Lacrosse Forum
Baseball Forum
SnowBoarding Forum
Soccer Forum
MMA Forum


All times are GMT -4. The time now is 05:09 PM.


Powered by vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.2
Webmaster Forums
Web Hosting | Chicago Web Hosting | Web Hosting