简体   繁体   中英

mysql_result resulting error in php

I am just shifting my database from MS-Access to mysql

I am using the following code (part of related code only) to retrieve data from mysql

$con = mysql_connect("localhost","abc","abc@123");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }


  $conn= mysql_select_db('xyz', $con);
if (!$con) {
    die ('Can\'t connect to database : ' . mysql_error());
}

$sql="SELECT * FROM Inventory where Text5='y' OR Text5='Y'  ";
$rs=mysql_query($sql);
if (!$rs)
  {exit("Error connecting database,,,");}

while (mysql_fetch_row($rs))
//while (!$rs->EOF)
  {
        $ASIN=trim(mysql_result($rs,"ASIN"));

        $LocalSKU = trim(mysql_result($rs,"LocalSKU"));

        //$ASIN=trim($rs->fields[120]);
        if(trim($ASIN)!=""){
            //include('funtions.php');
            $shipArray = shipingPrice($ASIN);
            $Price=round((mysql_result($rs,"Price")),2);
            $Price2=round((mysql_result($rs,"Price2")),2);  

but when I run the script I get the following error message

Warning: mysql_result() expects parameter 2 to be long, string given in C:\\wamp1\\www\\nathan\\amazonPrice.php on line 67

basically, from the query result, I want to select the value of ASIN and LocalSKU fields to process it further..

can somebody suggest me what I am doing wrong here?

http://php.net/mysql_result

The second parameter of mysql_result is the row you want. It's NOT a string field.

Your code is rather horrible. You could vastly simplify it with:

$row = mysql_fetch_assoc($rs);
$price = $row['price'];
$pric2 = $row['price2'];
etc...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM