Unknown column 'b.id2' in 'Where clause'

Asked

Viewed 97 times

-1

You’re making that mistake:

Unknown column 'b.id2' in 'Where clause'

Php packages.

include ("config.php");
$tabla2 = mysql_query("SELECT * FROM  tb_buyref b, tb_refset r  WHERE r.id=".$id." AND b.id2=".$id)  or die(mysql_error()); // selecciono todos los registros de la tabla usuarios, ordenado por nombre
while($registro2 = mysql_fetch_assoc($tabla2)){

Someone could help me?

  • 1

    id2 does not exist in table, prints sql and direct test in database.

  • @lost the table must exist, what does not exist is the id2 field in table tb_buyref

  • Try to explain the purpose of the code and the context of the problem. It seems that you want to make a join in tables, for this it is necessary that both have some column id in common. The query can be rewritten as: SELECT * FROM tb_buyref b INNER JOIN tb_refset r ON b.id = r.id WHERE b.id = $id

2 answers

1

Unknown column 'b.id2' in 'Where clause'

The error says that there is no "id2" column in table "tb_buyref", the "b" in your query is only an alias for the table.

Checked the table structure?

  • 1

    No error appeared but also did nothing.

  • 2

    @user7329 the id2 field exists in table tb_buyref? already confirmed?

  • There is so I changed the script from id2 to id, no more error appears when I will run a function ex: Delete Referred it appears a blank page.

  • 1

    If there is no remove this condition "AND b.id2=". $id", but first try to check why of this condition or if there is another id field to replace.

  • @user7329 then the problem was solved, it was the column "id2" that did not exist but the column "id". Now the problem is another, probably the query is not returning any results. I do this, after "mysql_query" check if any entries were found, as follows: $num_rows = mysql_num_rows($tabla2); die("we found $num_rows records");

0

try to change the column name as added below, probably you got confused at the time of putting the name and put id2, but this depends on the nomenclature you put, if not for sure enter here the structure of your database

$tabla2 = mysql_query("SELECT * FROM  tb_buyref b, tb_refset r  WHERE r.id=".$id." AND b.id=".$id)  or die(mysql_error());

Browser other questions tagged

You are not signed in. Login or sign up in order to post.