Jump to content

[SOLVED] Reversing Script to Preventing SQL Injection


Akenatehm

Recommended Posts

Hey Guys, I have this script that deletes records from the database and is set to prevent SQL Injection but I need to edit the insert record script to also prevent SQL Injection.

 

Here is the script:

 

$insert="INSERT INTO `users` (username,password,email) values('$username','$password','$email')";

 

Here is the Delete Script with MySQL Injection Prevention Already:

 

<?php
$delete="DELETE FROM `users` WHERE 'username' = ".mysql_real_escape_string($username)." OR 'email' = ".mysql_real_escape_string($email)."";
?>

Link to comment
Share on other sites

They are a type specifier that says what type the argument data should be treated as.

 

%s means that it will treat what ever value that goes that as a string. Since I used the sprintf function, those are REQUIRED and if removed will not work properly.

 

As you can see, there are 3 %s and that means you need 3 additional parameters passed to sprintf, which I did with the three mysql_real_escape_string functions.

 

Here is the list of other values other than %s:

 

    *  % - a literal percent character. No argument is required.

    * b - the argument is treated as an integer, and presented as a binary number.

    * c - the argument is treated as an integer, and presented as the character with that ASCII value.

    * d - the argument is treated as an integer, and presented as a (signed) decimal number.

    * e - the argument is treated as scientific notation (e.g. 1.2e+2). The precision specifier stands for the number of digits after the decimal point since PHP 5.2.1. In earlier versions, it was taken as number of significant digits (one less).

    * u - the argument is treated as an integer, and presented as an unsigned decimal number.

    * f - the argument is treated as a float, and presented as a floating-point number (locale aware).

    * F - the argument is treated as a float, and presented as a floating-point number (non-locale aware). Available since PHP 4.3.10 and PHP 5.0.3.

    * o - the argument is treated as an integer, and presented as an octal number.

    * s - the argument is treated as and presented as a string.

    * x - the argument is treated as an integer and presented as a hexadecimal number (with lowercase letters).

    * X - the argument is treated as an integer and presented as a hexadecimal number (with uppercase letters).

 

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.