-2

i can't make it work this simple query,it gives me my "die" error

mysql_select_db("minigest_dev" , $con);
$query = "  SELECT * "
    . "FROM anag_c_indirizzi"
    . "WHERE id_cliente = '1';";
$result = mysql_query($query, $con) or
    die("query non valida: ". mysql_error());

where is the mistake?

4
  • Print out the generated statement and you'll see for yourself.
    – user330315
    Nov 27, 2013 at 10:51
  • 1
    You need a space before your WHERE clause. Nov 27, 2013 at 10:51
  • Did you actually read the error the die statement was outputting? Nov 27, 2013 at 10:52
  • @ciaoben Next time, please print out the error details you are receiving as well. It greatly helps us to determine how we'll be able to help you more. Nov 27, 2013 at 10:53

3 Answers 3

4

When your query is concatenated, it becomes SELECT * FROM anag_c_indirizziWHERE id_cliente = '1'. You need to add a space so that it becomes [...] anag_c_indirizzi WHERE [...].

0
0

You can try this.

Your mistake that you are show error in or condition.

Note : $query = " SELECT * " . "FROM anag_c_indirizzi" . "WHERE id_cliente = '1';";

multiple semicolon not allow in sql plz remove one semicolon(;)

mysql_select_db("minigest_dev" , $con);

   $query = "   SELECT * 
           FROM anag_c_indirizzi
           WHERE id_cliente = '1'";

   $result = mysql_query($query);

if (!$result) {
    die('query non valida:' . mysql_error());
}
0

When you append you need to take care of string. Just give one space WHERE clause starts.

mysql_select_db("minigest_dev" , $con);
$query = " SELECT * "
       . " FROM anag_c_indirizzi "
       . " WHERE id_cliente = 1;";
$result = mysql_query($query, $con) or
         die("query non valida: ". mysql_error());

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.