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 8604541
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T02:35:55+00:00 2026-06-12T02:35:55+00:00

I have two files: cart_function.php function get_product_name($pid){ $result = mysql_query(SELECT product_name FROM product_table WHERE

  • 0

I have two files:

cart_function.php

function get_product_name($pid){
    $result = mysql_query("SELECT product_name FROM product_table WHERE product_id='".$pid."'", $link);
    $row = mysql_fetch_array($result);
    return $row['product_name'];
}

cart.php

<?php
    include('cart_function.php');
    $pid = $_GET['product_id'];
    $pname = get_product_name($pid);
    echo $pname;
?>

After I execute the cart.php, it shows an error

supplied argument is not a valid MySQL-Link resource’

If I run the query directly in MySQL database it works perfectly. If I used the get_product_name() function directly in cart.php, again it’s not working. But if I remove the function and use the code below, it works:

<?php
    $pid = $_GET['product_id'];
    $result = mysql_query("SELECT product_name FROM product_table WHERE product_id='".$pid."'",$link);
    $row = mysql_fetch_array($result);
    $pname = $row['product_name'];
    echo $pname;
?>

Why?

  • 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-06-12T02:35:56+00:00Added an answer on June 12, 2026 at 2:35 am

    The problem is here:

    function get_product_name($pid){
        $result = mysql_query("SELECT product_name FROM product_table WHERE product_id='".$pid."'",
                              $link);
    

    You have written $link, but its value is not supplied. You have to pass this value in the function argument as you are passing $pid value, like this:

    function get_product_name($pid,$link){
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two files like below SomeClass.php class SomeClass { public function display() {
I have two files client.php and server.php. The client file send a HTTP request
I have two files 1 - index.php 2 - main.php index.php call to main.php
i have two files:(localhost/template/) index.php template.php each time when i create an article(an article
I have two files: index.php /lib/user.php Index contains the form: <div class=<? echo $msgclass;
I have two files: first.php: #!/usr/bin/php <?php exit(Unable); //1 #exit(1); //2 #exit(); //or exit(0)
I have two files say file1.php and file2.php. I have one php file named
I have two files: template.php: <div><?php echo $myVar; ?></div> controller class MyClass extends Base
I have two files: test.php and query.php. My server is lighttpd. In test.php I
I have two files from a C program. I guess both belong to quite

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.