Reply
Cant delete a row in mysql ? very odd, see code!
Old 01-16-2009, 11:34 AM Cant delete a row in mysql ? very odd, see code!
Registered User

Posts: 255
Trades: 4
Hi all
I have a little script im building for online wars (Gaming)
Anyway from the php pages you can add to the DB and retrieve info from it, but wnat you cant do is delete it?...... if spent 2 days now trying to figuire this out ,and i now fear for the saftey of my comupter and of the window it may be flying out off

Code:
<?php require('../config.php');
$db = "$db_name";
$cid = mysql_connect($db_host,$db_username,$db_password);
if (!$cid) { echo("ERROR: " . mysql_error() . "\n"); }

 if ($task=="del") {
  $SQL = " DELETE FROM ca_war ";
  $SQL = $SQL . " WHERE id = $id ";
  mysql_db_query($db, $SQL, $cid);
 }
?>
<html>
<body bgcolor="000000">
</body>
<head>
 
</center>
 
<?
 $SQL = " SELECT * FROM ca_war ";
 $retid = mysql_db_query($db, $SQL, $cid);
 if (!$retid) { echo( mysql_error()); }
 else {
  echo ("<P><TABLE CELLPADDING=4>\n");
  while ($row = mysql_fetch_array($retid)) {
   $clan = $row["clan"];
   $id = $row["id"];
   echo ("<TR>");
   echo ("<TD><font color=ffffff>$clan</TD>\n");
   
   echo ("<TD><A HREF=\"remove.php?id=$id&task=del\">Delete</A></TD>");
   echo ("</TR>");
  }
  echo ("</TABLE>");
 }
?>
 
 
</HTML>
As i say i really cant see why its not working, its re loading itself and the browser then reads correct
Example http://www.limaservices.com/nochex/a...?id=3&task=del so it should have deleted it.....


Im prob looking to hard now so il throw it to you guys if i may

Thanks
Mark
internetking is offline
Reply With Quote
View Public Profile
 
 
When You Register, These Ads Go Away!
Old 01-16-2009, 04:56 PM Re: Cant delete a row in mysql ? very odd, see code!
amw_drizz's Avatar
Ultra Talker

Posts: 338
Name: Jon
Location: New York
Trades: 0
Why not change from this
PHP Code:
 if ($task=="del") {
  
$SQL " DELETE FROM ca_war ";
  
$SQL $SQL " WHERE id = $id ";
  
mysql_db_query($db$SQL$cid);
 } 
to this
PHP Code:
 if ($task=="del") {
  
$SQL "DELETE FROM ca_war WHERE id ="$id ;
  
mysql_db_query($db$SQL$cid);
 } 
__________________
AMW_Drizz
Dev Machine:: Apache 2.2.6 PHP 5.2.6 MySQL 5.1
amw_drizz is offline
Reply With Quote
View Public Profile Visit amw_drizz's homepage!
 
Old 01-16-2009, 05:06 PM Re: Cant delete a row in mysql ? very odd, see code!
jason_alan's Avatar
Super Talker

Posts: 101
Name: Jason
Location: Seattle, WA
Trades: 0
$id probably isn't set. If register_globals is off then you will have to set $id this way:
$id = $_GET['id'];

Btw, you might want to do some authorization checking on this script, cause anyone could use that link to delete everything from this db table
jason_alan is offline
Reply With Quote
View Public Profile
 
Old 01-16-2009, 05:08 PM Re: Cant delete a row in mysql ? very odd, see code!
jason_alan's Avatar
Super Talker

Posts: 101
Name: Jason
Location: Seattle, WA
Trades: 0
Oh, same with task:
$task = $_GET['task'];
jason_alan is offline
Reply With Quote
View Public Profile
 
Old 01-17-2009, 08:58 AM Re: Cant delete a row in mysql ? very odd, see code!
Registered User

Posts: 255
Trades: 4
Thanks to you both.

It seems like jason_alan you were spot on and i thank you.

As for your security advice, i aggree but am unsure of who to add authorization

Thanks

Mark
internetking is offline
Reply With Quote
View Public Profile
 
Old 01-17-2009, 09:16 AM Re: Cant delete a row in mysql ? very odd, see code!
Zycron's Avatar
Novice Talker

Posts: 10
Name: Keith
Trades: 0
For validating your input, you could use a regular expression:

PHP Code:
if($task=="del")


     if(
ereg("^([0-9]+)$"$id)) //id is an integer of at least 1 digit
     
{
          
$SQL "DELETE FROM ca_war WHERE id =" $id
          
mysql_db_query($db$SQL$cid);
     }

Zycron is offline
Reply With Quote
View Public Profile Visit Zycron's homepage!
 
Old 01-18-2009, 01:00 AM Re: Cant delete a row in mysql ? very odd, see code!
jason_alan's Avatar
Super Talker

Posts: 101
Name: Jason
Location: Seattle, WA
Trades: 0
Quote:
Btw, you might want to do some authorization checking on this script, cause anyone could use that link to delete everything from this db table
What I meant by that was that you don't want just anyone to be able to use this link:
remove.php?task=del&id=1
remove.php?task=del&id=2
remove.php?task=del&id=3
remove.php?task=del&id=4 ... etc

to wipe out all your records in that table. You should at least have a login form that will store user authorization in the $_SESSION, then check for this at the start of your script. There's many ways to do this, but that's just 1 example
jason_alan is offline
Reply With Quote
View Public Profile
 
Old 01-19-2009, 10:09 AM Re: Cant delete a row in mysql ? very odd, see code!
anderswc's Avatar
Super Talker

Posts: 132
Name: Will Anderson
Location: Terre Haute, IN
Trades: 0
also make sure you use the suggestion from Zycron, otherwise SQL injection could be used to do literally ANYTHING with your database!

make sure you secure your login as well if you're utilizing a database. addslashes is your friend here, use it!
__________________
Will Anderson
It's An Anderson | Twitter | Anderson Web Solutions
anderswc is offline
Reply With Quote
View Public Profile Visit anderswc's homepage!
 
Reply     « Reply to Cant delete a row in mysql ? very odd, see code!
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 



Page generated in 0.15083 seconds with 13 queries