php - get url not working properly -


i working on following code pulling information db.

this want code do:

  • a user logs in.
  • if image belongs user, after db queried image requested , found query belongs user must show up.
  • if image number requested not belong user, page must either error out or redirect.

this code:

$id = mysql_real_escape_string(@$_get['uid']); // user ref # $imgid = mysql_real_escape_string(@$_get['img']); // img ref # $query = mysql_query("select mypage.*, img.*                        img                        join mypage on img.user = mypage.user mypage.id = '$id'");  if ((mysql_num_rows($query) == 0)) {       header("location:page.php?uid=$id");         die(mysql_error()); } else {    while($rows = mysql_fetch_array($query)) {      $img = $rows['img'];     $pfname = $rows['pfname'];     $plname = $rows['plname'];     $puser = $rows['puser'];     $description = $rows['description'];     $ppid_image_name = $rows['ppid_image_name'];   }  

when run code, able print out correct result. problem url part.

let's url http://www/profile.php?uid=5&img=4... img=4, referenced image belongs user, yes, image shows when call.
if img=5, referenced image not belong yet shows under user, not when query result.
if img=12, ref image number not exists in db, error instead of redirect.

i seem having problems conocation part of url. &img=ref#

i'm not sure if problm here: if ((mysql_num_rows($query)==0)). tried if ((mysql_num_rows($query)!=imgid)) redirect, doesn't work.

what doing wrong?

1) there error in query , use left join instead of join

mysql_query("select mypage.*, img.*                          img                          left join mypage on img.user = mypage.user mypage.id = '$id'"); 

2) test :

  while($rows = mysql_fetch_array($query)) {      $img = $rows['img'];     $pfname = $rows['pfname'];     $plname = $rows['plname'];     $puser = $rows['puser'];     $description = $rows['description'];     $ppid_image_name = $rows['ppid_image_name']; } if (!isset($img)) {       header("location:page.php?uid=$id");         die(mysql_error()); 

Comments

Popular posts from this blog

c++ - Is it possible to compile a VST on linux? -

java - Output of Eclipse is rubbish -

jquery - Confused with JSON data and normal data in Django ajax request -