Monday, December 17, 2012

Escapes Special Characters in a String for use in an SQL statement

          Today I face a big problem in my recent project with this Quotes ( ' ).  I can't submit my data into database which have contain this Quotes ( ' )  . . . . .  :'(
When i Set my $value= ' my father's ';
with this ( ' ) than i face an error. That  is it -

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 's 

Than What...?  What can I do ?

mysql_real_escape_string — Escapes special characters in a string for use in an SQL statement


mysql_real_escape_string() calls MySQL's library function mysql_real_escape_string, which prepends backslashes to the following characters: \x00, \n, \r, \, ', " and \x1a.

This function must always (with few exceptions) be used to make data safe before sending a query to MySQL.

Example :
  1.  $description=$_POST['description'];
  2. $escaped_description=mysql_real_escape_string($description);

  3. $sql= "INSERT INTO TABLE_NAME (post_description)
  4. VALUES                            ('".$escaped_description."')";


This Works Perfectly .....  

  Note : This would allow anyone to log in without a valid password.

Thursday, December 13, 2012

WAMP and Skype Conflict

Recently I discover a conflict between Skype and WampServer that I thought I would Share.  Both of them  use port 80 which causes the conflict... :D . If you run Skype before running Wamp, then Apache will not run. If you go to a site on localhost or 127.0.0.1 , you will probably get a blank screen.
..What Happen..?
The solution is pretty simple. Just make sure you start all services on WAMP before you open Skype. If Skype is disconnected it will work fine. You can then connect Skype once Wamp is running....
--- Really too easy....

But..
A much better solution than starting WAMP before Skype is to follow the advice ---
So, Why not...?
In skype if you click "tools " then "options" and connection down the left, untick the box "use port 80 and 443 as alternative incoming ports"

That worked  nicely and haven't looked back  :)