0

This is very strange, but when I add the mysql_real_escape_string it doesn't load the page, this is the code that I load like this:

$('.abandalink').click(function(){  
    var codigo_membro = $(this).attr('codigomembro');
    $('#change').load('membrosbanda.php?codigo='+codigo_membro); 
});

And this is the membrosbanda.php

$id=$_GET['codigo']; 
$conexion=mysql_connect(HOSTNAME,USER,PW) or  die("Problemas en la conexion");
mysql_select_db("bandasideral4",$conexion)  
  or  die("Problemas en la selección de la base de datos");
$registros=mysql_query("SELECT * FROM abanda where codigo='$codigo'") or
  die("Problemas en el select:".mysql_error());

if I add $id=$_GET['codigo']; to $id = mysql_real_escape_string($_GET['codigo']); it stops working

5
  • in what way does it "stop working"?
    – Cfreak
    Commented Mar 29, 2012 at 13:53
  • 5
    Your MySQL is listening on port 3306 and you just posted your host (ip), username, and password. I just logged in to test it only. You should change your password asap
    – Paul
    Commented Mar 29, 2012 at 13:55
  • 1
    jeroen is right in his answer, but it would be even better to use prepared statements using PDO or MySQLi.
    – GolezTrol
    Commented Mar 29, 2012 at 13:58
  • @GolezTrol I completely agree...
    – jeroen
    Commented Mar 29, 2012 at 13:59

2 Answers 2

4

You need to connect to a database first, before that mysql_real_escape_stringis not available.

From the manual:

Note:

A MySQL connection is required before using mysql_real_escape_string() otherwise an error of level E_WARNING is generated, and FALSE is returned. If link_identifier isn't defined, the last MySQL connection is used.

0

If you puts codigo in $id, your sql must be SELECT * FROM abanda where codigo='$id'

a better style would be this: $id_s =mysql_real_escape_string($_GET['codigo']);

So you have all your *_s variables being escaped for sql stuff, and all normal variables being tainted data.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.