Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6109327
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:23:32+00:00 2026-05-23T14:23:32+00:00

I am working on the following code that is pulling information from a DB.

  • 0

I am working on the following code that is pulling information from a DB.

This is what i want the code to do:

  • A user logs in.
  • If the image belongs to the user, after the db is queried only this image requested and found by the query that belongs to the user must show up.
  • if the image number requested does not belong to the user, the page must either error out or redirect.

This is the code:

$id = mysql_real_escape_string(@$_GET['uid']); // get user ref #
$imgid = mysql_real_escape_string(@$_GET['img']); // get img ref #
$query = mysql_query("SELECT mypage.*, img.* 
                      FROM img 
                      JOIN mypage ON img.user = mypage.user WHERE 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 I run the code, I am able to print out the correct result. The problem is the get URL part.

Let’s say the URL is http://www/profile.php?uid=5&img=4... img=4, the referenced image belongs to the user, so yes, this image shows up when call.
If img=5, this referenced image does not belong but yet it shows up under the user, but not when i query the result.
If img=12, a ref image number that does not exists in the DB, I get an error instead of a redirect.

I seem to be mostly having problems with the conocation part of the url. &img=ref#

I’m not sure if the problm is here: if ((mysql_num_rows($query)==0)).
I tried if ((mysql_num_rows($query)!=imgid)) redirect, this doesn’t work.

What am I doing wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T14:23:32+00:00Added an answer on May 23, 2026 at 2:23 pm

    1) There is an error in your query , Use Left Join instead of Join

    mysql_query("SELECT mypage.*, img.* 
                            FROM img 
                            LEFT JOIN mypage ON img.user = mypage.user WHERE mypage.id = '$id'");
    

    2) Test this :

      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());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working with some old PHP code that has a lot of the following:
I'm trying to get the following code working: string url = String.Format(@SOMEURL); string user
I have the following code that isn't working in IE, any thoughts? <script type=text/javascript
I have following code that is generating random no. between 1 to 10. This
I have the following code that I want to return to a variable t
I'm working on some code that calls a service. This service call could fail
I have the following code that I am working on for my college assignment.
I'm working with the following code that contains a JProgressBar inside of an AbstractTableModel.
I am working with some code that uses an OleDbConnection to load data from
I have the following code that is working on my local machine (Win 7,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.