Skip to main content

mysql_real_escape_string

mysql_real_escape_string

In a nutshell, it makes a string safe to be entered into a database….

For example:

$email = 'myemail@domain.co.uk'; // This could come from a form, etc.
$result = mysql_query("SELECT * FROM `userTable` WHERE `userEmail`= '".mysql_real_escape_string($email)."'");

This example checks to see if an email address is in the userTable. Without mysql_real_escape_string, the email entered via a form could be an attempt to SQL inject and delete or alter your database.

Another solution is to create a function, especially useful if you include a sitewide ‘config’ or settings file at the top of your page…

function escape_data($data) { return mysql_real_escape_string(trim($data)); }
Main Category
  • PHP
  •  
 
Jon Moore

Search form

Jon Moore

Tips 'n' Snips

 
  • Home
  • General
  • Drupal
    • Drupal 6
    • Drupal 7
    • Module Building
  • HTML & CSS
  • Javascript
  • jQuery
  • PHP
    • CodeIgniter
    • Handy Functions
    • MySQL
  • WordPress
  • About

BBC Technology News

  • Heathrow: Man charged with flying drone near airport
  • Girl Scouts of America offer badge in cybersecurity
  • Rise in nude photos sent to phones on public transport
  • Are these the faces of the future?
  • Zimbabwe blocks Facebook, WhatsApp and Twitter amid crackdown
More

Sitepoint

  • How to Build Your First Static Site with Gatsby
  • Customer Journey Maps: A Day in the Life of a Customer
  • How to Take JavaScript Beyond the Web in 2019
  • Check out the 6 Best Productivity Apps for Designers
  • 7 Awesome Wireframing Tools You Should Be Using
More

Heart Internet

  • Did he really just say that? How to deal with an obnoxious client
  • Product management for designers
  • Talking to your clients about WordPress plugin security
  • The developer’s guide to native web animation
  • Are you seeing clearly? The role of visual thinking in creative work
More
 

Backend Coders

  • PHP
  • Handy PHP Functions
  • PHP MySQL

Frontend Coders

  • HTML & CSS
  • jQuery
  • Javascript

CMS/CMF Systems

  • Drupal
  • Drupal 6 Specific
  • Drupal 7 Specific
  • Drupal Module Building
  • WordPress

About

  • Home
  • About
 

© Jon Moore 2019

All stock images are from www.istockphoto.com