Page 1 of 1

**SOLVED** Retrieve data associated to variable from

Posted: Tue Apr 19, 2005 7:01 am
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>";

Posted: Tue Apr 19, 2005 7:21 am
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.

Posted: Tue Apr 19, 2005 7:24 am
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!