**SOLVED** Retrieve data associated to variable from

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
facets
Forum Contributor
Posts: 273
Joined: Wed Apr 13, 2005 1:53 am
Location: Detroit

**SOLVED** Retrieve data associated to variable from

Post by facets »

Hi,

I've managed (with some help) to pass a variable to a popup window. now i'm having some troubles retrieving the associated table data. If I set 'WHERE stockId = '2''; I get the data I need, but this is not the right way to do it. I am unsure of where to progress with this? Does any one have a link or some examples I can view?

tks, Will

Code: Select all

// View Record Function
    function viewFaceStock() {

        html_header();
        
        $stockId = $_GET['stockId'];
       
        print_r($_SESSION);
        print_r($_POST); 
        
        $query = "SELECT stockId, description, basisWeight, caliper FROM austock WHERE stockId = '$stockId'";
      
        $result = mysql_query($query);
       
            if(!$result) error_message(sql_error());
          
        $query_data = mysql_fetch_array($result);
        $stockId = $query_data["stockId"];

        echo $stockId;
        echo "<br>";
Last edited by facets on Tue Apr 19, 2005 7:01 pm, edited 1 time in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

echo $query after you set it.

line 15: unless you have a custom written function (sql_error()), I think you want to use mysql_error() instead.
facets
Forum Contributor
Posts: 273
Joined: Wed Apr 13, 2005 1:53 am
Location: Detroit

Post by facets »

Fixed.
I was assigning the stockname to stockId earlier in my code. DOH!
the echo displayed the stcokname not the stockId.

re:sql_error()

Code: Select all

function sql_error() {
   global $MYSQL_ERRNO, $MYSQL_ERROR;

   if(empty($MYSQL_ERROR)) {
      $MYSQL_ERRNO = mysql_errno();
      $MYSQL_ERROR = mysql_error();
   }
   return "$MYSQL_ERRNO: $MYSQL_ERROR";
}
does that look ok?
I basically snatched this one from a php book ;)

Cheers, for your continued support!
Post Reply