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

  • Home
  • SEARCH
  • 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 602863
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T16:52:07+00:00 2026-05-13T16:52:07+00:00

I am trying to pass multiple variables in a URL in PHP to GET

  • 0

I am trying to pass multiple variables in a URL in PHP to GET some info, but I don’t think it’s working.

$allowedFunctions = array(
   'returnAllProducts',
   'refreshCurrentProduct'

);


$IDNUM = $_GET[ 'idNum' ];


$functionName = $_GET[ 'func' ];

if( in_array( $functionName, $allowedFunctions ) && function_exists( $functionName ) )
{
    $functionName();
}

Then I have the refreshCurrentProduct function:

function refreshCurrentProduct() { 
$dbh=mysql_connect ("DATABASE","USER", "PASS") or die('I cannot connect to the database because:'. mysql_error());

mysql_select_db("TABLE");

$query = "SELECT `ID` FROM `PRODUCTS`";

$result = mysql_query($query) or die('Query failed:'.mysql_error());

$DB_STOCK = mysql_query("SELECT `STOCK` FROM `PRODUCTS`") or die('Query failed:'.mysql_error());

$DB_SHORT = mysql_query("SELECT `MYNAME` FROM `PRODUCTS`") or die('Query failed:'.mysql_error());

$DB_LONG = mysql_query("SELECT `DESCRIPTION` FROM `PRODUCTS`") or die('Query failed:'.mysql_error());

$DB_PRICE = mysql_query("SELECT `PRICE` FROM `PRODUCTS`") or die('Query failed:'.mysql_error());

$DB_SHIP = mysql_query("SELECT `SHIPPING` FROM `PRODUCTS`") or die('Query failed:'.mysql_error());


$ID = mysql_result($result,$IDNUM,"ID");
    $STOCK = mysql_result($DB_STOCK,$IDNUM,"STOCK");
    $SHORT = mysql_result($DB_SHORT,$IDNUM,"MYNAME");
    $LONG = mysql_result($DB_LONG,$IDNUM,"DESCRIPTION");
    $PRICE = mysql_result($DB_PRICE,$IDNUM,"PRICE");        
    $SHIP = mysql_result($DB_SHIP,$IDNUM,"SHIPPING");

    echo '
    //echo $STOCK, $SHORT, etc....

    ';
 }

The URL I am using is products.php?func=refreshCurrentProduct&idNum=4

In theory, that should display from the row with 4 in it, however, it only displays the info from the first row. If I do a $IDNUM=5 within the function, it will display the 5th row, so something is wrong with how I pass the information.

Also, how do I create (for instance) $STOCK without having to have so much code in $DB_STOCK? Seems like there has to be a better way…

  • 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-13T16:52:07+00:00Added an answer on May 13, 2026 at 4:52 pm

    Why don’t you do (as others already mentioned , $IDNUM is not in the scope of the function):

    function refreshCurrentProduct() { 
        $dbh=mysql_connect ("DATABASE","USER", "PASS") or die('I cannot connect to the database because:'. mysql_error());
        mysql_select_db("TABLE");
    
        // If $_GET['idNum'] is not a number use 0
        $rowNumber = is_numeric($_GET['idNum']) ? $_GET['idNum'] : 0;
    
        $query = "SELECT ID, STOCK,  MYNAME, DESCRIPTION, PRICE, SHIPPING FROM `PRODUCTS`";
        $result = mysql_query($query);
    
        if(mysql_data_seek($result,  $rowNumber)) {
            // The result set has indeed at least $rowNumber rows
    
            $row = mysql_fetch_assoc($result);
    
            echo $row['ID'];
            echo $row['STOCK'];
            // ... etc ....
        }
        else {
            echo "No such row!";
        }
    }
    

    No need to hit the database six times! Of course you need to add error handling.

    Btw. is the parameter idNum the same as the ID of the record in the database? If so, you can even further simplify:

    function refreshCurrentProduct() { 
        $dbh=mysql_connect ("DATABASE","USER", "PASS") or die('I cannot connect to the database because:'. mysql_error());
        mysql_select_db("TABLE");
    
        // If $_GET['idNum'] is not a number use 0
        $id = is_numeric($_GET['idNum']) ? $_GET['idNum'] : 0;
    
        $query = "SELECT ID, STOCK,  MYNAME, DESCRIPTION, PRICE, SHIPPING FROM `PRODUCTS` WHERE ID = $id";
        $result = mysql_query($query);
    
        if (mysql_num_rows($result) == 0) {
           echo "No rows found, nothing to print";
           return;
        }
    
        $row = mysql_fetch_assoc($result);
    
        echo $row['ID'];
        echo $row['STOCK'];
        // ... etc ....
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 382k
  • Answers 382k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer From the documentation, the default font is Times New Roman,… May 14, 2026 at 10:35 pm
  • Editorial Team
    Editorial Team added an answer You will have to provide the keydown-search functionality yourself. For… May 14, 2026 at 10:35 pm
  • Editorial Team
    Editorial Team added an answer I've had a stab at doing this in python. It… May 14, 2026 at 10:35 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.