problem with php mysql

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
rameau1982
Forum Newbie
Posts: 1
Joined: Thu Nov 15, 2007 4:02 am

problem with php mysql

Post by rameau1982 »

I want to make a query into a db through a php script sending variables trough POST. With mysql_error() it says that I have an error in the query : Select...
Can somebody help me?

Code: Select all

<?
extract($_POST);
$ref_art=trim($ref_art);
$exi_art=trim($exi_art);

 if (!$ref_art || !$exi_art)

{

   echo 'No has introducido la referencia o las unidades';

   header("Location: index.php");

}

$sref_art = addslashes($ref_art);

$exi_art = addslashes($exi_art);


@ $conn=mysql_pconnect("localhost","","");

if(!$conn){

    echo "no existe tal bd";

}

mysql_select_db("tienda");
echo "hola";
//Ejecucion de la sentencia SQL
$query = "Select * From fal_art Where ref_art = '$ref_art'";
$result = mysql_query($query);
if($result){
    $filas = mysql_num_rows($result);
    echo "$filas";
}else{
    echo mysql_error();
}
?>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Post the entire error output by mysql_error() please.

Also, note that addslashes() is not a suitable protection against SQL injection. Nor is it recommended to use extract() as the variables you are referencing may still not exist. Use isset() or array_key_exists() instead help set the value.
Post Reply