Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>First point: If you're getting an error from <code>mysql_real_escape_string()</code>, it's because you are calling the function before you're connected to the database.</p> <p>It looks like you connect to the database right before you run a query. So anything you do before you call your <code>mm_mysqlquery()</code> function won't have a connection.</p> <p>The <code>mysql_real_escape_string()</code> function needs a live connection to the database, so it can do the right kind of escaping with respect to the connection's character set. So you need to connect <em>before</em> you do escaping.</p> <p>It's better to do that anyway, because if you make several queries during the course of a single PHP request, it's less overhead to connect <em>once</em> and use the same connection for all your queries.</p> <p>Second, please don't take suggestions to use <code>addslashes()</code> -- it does not do the same thing as <code>mysql_real_escape_string()</code>. The two are not interchangeable. You should get into the habit of using <code>mysql_real_escape_string()</code>.</p> <p>Third, your <code>sani()</code> function shows a common misconception.</p> <pre><code>function sani($string){ $string = strip_tags($string); $string = htmlspecialchars($string); $string = trim(rtrim(ltrim($string))); $string = mysql_real_escape_string($string); return $string; } </code></pre> <p>The common misconception is that you need all these functions to make a string safe in an SQL statement. You don't. Only <code>mysql_real_escape_string()</code> is necessary. All the other functions in this example do nothing to protect against SQL injection.</p> <p>Those functions are useful if you output a string in an HTML presentation and you want to reduce the risk of XSS attacks, but then <code>mysql_real_escape_string()</code> is irrelevant.</p> <p>Use each type of sanitizing method in its appropriate context.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload