php - retrieving data from database does not work on this code -


categories databse table:

id  | name   1   | electronics 2   | automotive 

classifieds database table:

id  user_id  category_id    cover          title       price    description  102  1       2              iamges/1.jpg    blabla     10      blablabla 

i error saying: notice: undefined variable: name1 in **\post.php on line 49

$id = $_get['id']; $res2 = mysql_query("select * `classifieds` `id` = '" . $id . "' limit 1");  if($res2 && mysql_num_rows($res2) > 0){     while($row = mysql_fetch_assoc($res2)){         $id = $row['id'];         $user_id = $row['user_id'];         $category_id = $row['category_id'];         $price = $row['price'];         $cover = $row['cover'];         $title = $row['title'];         $description = $row['description'];         $profile_data = user_data($user_id, 'username');          $res3 = mysql_query("select * `categories` `id` = '" . $category_id . "' limit 1");         if($res3 && mysql_num_rows($res3) > 0){             while($row1 = mysql_fetch_assoc($res3)){                 $id1 = $row1['id'];                 $name = $row1['name'];             }         }       } }else{     echo 'error'; }echo $name; 

why error echo $name1; ?

you should print query , run in php myadmin driectly , see if returns correct result.

you threewhile loops contains same $row. please change below 1 else

 while($row = mysql_fetch_assoc($res2)){  ,     while($row = mysql_fetch_assoc($res3)){   ------^  

change else $row3

  while($row3 = mysql_fetch_assoc($res3)){         $id = $row3['id'];         $name = $row3['name'];     } 

Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -