Jump to content

[Sql Injection] Need To Redo My Query And/or The Form


Swarfega

Recommended Posts

Hi.

 

 

I've established a possible SQL Injection on my site, and I'm curious as to what the best type of fix would be for it.

 

Here's the SQL Error on the Page:

 

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '.$_SESSION['SESS_MEMBER_ID'].'', 'Klotterplanket')' at line 1

 

And here's the query

$deletedmessage = $getdata['message'];
$sql = "DELETE FROM klotterplanket WHERE id='".$_GET['id']."'";
mysql_query($sql) or die(mysql_error());
$sql = "INSERT INTO adminlogs(uid, name, message, vart) VALUES('".$_SESSION['SESS_MEMBER_ID']."', '$fullname', '".$deletedmessage."', 'Klotterplanket')";
$query = mysql_query($sql) or die(mysql_error());
if($query) {
header("Location: klotterplank.php");
echo '<script>alert("Meddelande Borttaget!")</script>';
} else {
echo '<script>alert("Något gick snett!") </script>';
header("Location: klotterplank.php");
}

 

The Deletion part works flawlessly, since that does not include the textarea of the Form. $getdata['message'] = form textarea value.

 

 

My first thought was to use str_replace on the textarea if the string contains '.$ or '. $ or ' . $ or ' .$ but I was wondering if anyone knows some better ideas?

Link to comment
Share on other sites

Don't just mysql_real_escape_string as its not proper protection.

 

You can do a number of things:

  • Validation
  • Sanitation
  • Type casting
  • Prepared statements (highly recommended)

Now Google your heart out to find out what each is.

 

I can't see why your query shouldn't work. What's the contents of the session variable?

Edited by CPD
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.