SQL delete query
mdb Offline
Junior Member
**
Posts: 27
Joined: May 2012
Post: #3
RE: SQL delete query
Okay so I found a tutorial this morning and worked on it a little. Basically, following the tutorial, I placed an html link beside each row in the while loop that looks like this:

Code:
<a href="delete_ban.php?table={$table}&name={$row['name']}&ip={$row['ip']}&ban={$row['ban']}&banadded={$banadded}" onclick="return confirm('Are you sure you want to delete this ban from the database?');"><img src="/images/no_greyscale.png" alt="Delete" title="Delete" onmouseover="this.src='/images/no.png';" onmouseout="this.src='/images/no_greyscale.png';" /></a>


Then inside delete_ban.php I grab the information from the url by doing this:

Code:
1
2
3
4
5
6
7
$name = $_GET['name'];
$ip = $_GET['ip'];
$ban = $_GET['ban'];
$banadded = $_GET['banadded'] - 5487365;
$banadded = $banadded / 2;

$delete = mysql_query("DELETE FROM $table WHERE name='$name' AND AND ip='$ip' AND ban='$ban' AND banadded='$banadded'  LIMIT 1");


Everything works based on that. However there are a few things I am questioning:

1. Is it safe to pass information like that to a url without sanitizing it a bit?
Would using $name = htmlspecialchars($name) be a good idea to do, or would that at times make that variable mismmatch with what is inside the sql table? Thus resulting in the row not being successfully deleted.

2. How would I stop regular users from basically guessing the link and having a field day banning information from that sql? With that, I assume they could just delete a row on the table by following the link http://www.mywebsite.com/delete_ban.php?...http://www.mywebsite.com/delete_ban.php?name=name_1&ip=11.222.333.44&ban=cheating&banadded (if that row actually existed inside the sql table).
I tried adding a little security by having the banadded var (which inside the sql table is recorded as a unix time stamp) having a bit of calculations added to it, which the user obviously wouldn't know the formula I used. And then taken away on the delete_ban page so that it's correctly able to find it in the database. If that makes sense? But i'm not sure if that's a lame form of security or not, I would assume there's better measures I can take?

10-22-2012 03:00 AM
Find all posts by this user Quote this message in a reply

« Next Oldest | Next Newest »

Messages In This Thread
SQL delete query - mdb - 10-21-2012, 05:30 PM
RE: SQL delete query - ZiNgA BuRgA - 10-21-2012, 10:01 PM
RE: SQL delete query - mdb - 10-22-2012 03:00 AM
RE: SQL delete query - ZiNgA BuRgA - 10-22-2012, 09:14 AM
RE: SQL delete query - mdb - 10-23-2012, 09:40 AM
RE: SQL delete query - ZiNgA BuRgA - 10-24-2012, 08:19 AM
RE: SQL delete query - devid456 - 07-06-2013, 12:45 AM

 Standard Tools
Forum Jump: