Jump to content


Photo

mysqli_fetch_array()


  • Please log in to reply
2 replies to this topic

#1 minneapolis

minneapolis
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 14 April 2006 - 01:59 AM

I have this weird error:::

Call to a member function fetch_array() on a non-object .

code is the following:::

//connect to the DB
$connect = new mysqli("localhost","ics325sp0604", "13855", "ics325sp0604" );

.....(CUT)

//insert information captured

$query = "SELECT FROM carttemp WHERE carttemp_sess='$sessid'";
$results = mysqli_query($connect, $query);

//put data in the DB
while ($row = mysqli_fetch_array($results)) { //line 105
extract($row);
$query4 = "INSERT INTO orderdet(
orderdet_ordernum, orderdet_qty, orderdet_prodnum)
.......(CUT)


The error is


Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in /home/students/ics325sp06/ics325sp0604/public_html/project4/checkout3.php on line 105
Step 1 - Please Enter Billing and Shipping Information
Step 2 - Please verify that your order is accurate
Step3 - Order Confirmation and Receipt

i tried several combination like:

$row = $connect->fetch_array($results)....
or
$row = $results->fetch_array()

But NO GO...
Can anybody help...

Thanks again





















#2 toplay

toplay
  • Staff Alumni
  • Advanced Member
  • 973 posts

Posted 14 April 2006 - 02:21 AM

Always check for errors before executing any subsequent mysql related commands. If you did that, you would see that you have not selected any columns, and hence that's your error in the SQL. Also, if you're going to use extract() might as well just use the fetch by association. Below I used "*" to retrieve all columns from the table.

.
.
.
$query = "SELECT * FROM carttemp WHERE carttemp_sess='$sessid'";
$results = mysqli_query($connect, $query) or die("SQL: $query Error: " . mysqli_error());

//put data in the DB
while ($row = mysqli_fetch_assoc($results)) { //line 105
extract($row);
.
.
.
}


#3 minneapolis

minneapolis
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 14 April 2006 - 04:37 AM

toplay thanks for the prompt reply, however when i do what you suggested , the only info i get is :

Step 1 - Please Enter Billing and Shipping Information
Step 2 - Please verify that your order is accurate
Step3 - Order Confirmation and Receipt



?php
session_start();
//connect to the DB
$connect = new mysqli("localhost","ics325sp0604", "13855", "ics325sp0604" );

//declare the necessary variables
$firstname = $_POST['firtsname'];
$lastname = $_POST['lastsname'];
$add1 = $_POST['add1'];
$add2 = $_POST['add2'];
$city = $_POST['city'];
$state = $_POST['state'];
$zip = $_POST['zip'];
$phone = $_POST['phone'];
$fax = $_POST['fax'];
$email = $_POST['email'];
$shipfirst = $_POST['shipfirst'];
$shiplast = $_POST['shiplast'];
$shipadd1 = $_POST['shipadd1'];
$shipadd2 = $_POST['shipadd2'];
$shipcity = $_POST['shipcity'];
$shipstate = $_POST['shipstate'];
$shipzip = $_POST['shipzip'];
$shipphone = $_POST['shipphone'];
$shipemail = $_POST['shipemail'];
$total = $_POST['total'];
$sessid = session_id();
$today = date("y - m- d");

// Assign a CU Number
$query = "SELECT FROM customers WHERE 
    (customers_firstname = '$firstname' AND
    customers_lastname = '$lastname' AND    
    customers_add1 = '$add1' AND
    customers_add2 = '$add2' AND
    customers_city = '$city')";

$results = $connect->query($query);
$rows = $results->num_rows;

if ($rows < 1) {
    $query2 = "INSERT INTO customers (
        customers_firstname, customers_lastname, customers_add1,
        customers_add2, customers_city, customers_state,
        customers_zip, customers_phone, customers_fax,
        customers_email)
        VALUES (
        '$firstname',
        '$lastname',
        '$add1',
        '$add2',
        '$city',
        '$state',
        '$zip',
        '$phone',
        '$fax',
        '$email')";

    $insert = $connect->query($query2);
    $custid = $connect->insert_id;

}

//CU exists ??

if ($custid) {
    $customers_custnum = $custid;
}

$shipping = $total * 0.25;

$query3 = "INSERT INTO ordermain (
    ordermain_orderdate, ordermain_custnum,
    ordermain_subtotal, ordermain_shipping,
    ordermain_shipfirst, ordermain_shiplast,
    ordermain_shipadd1, ordermain_shipadd2,
    ordermain_shipcity, ordermain_shipstate,
    ordermain_shipzip, ordermain_shipphone,
    ordermain_shipemail)
    
    VALUES (
    '$today',
    '$customers_custnum',
    '$total',
    '$shipping',
    '$shipfirst',
    '$shiplast',
    '$shipadd1',
    '$shipadd2',
    '$shipcity',
    '$shipstate',
    '$shipzip',
    '$shipphone',
    '$shipemail')";

$insert2 = $connect->query($query3);
$orderid = $connect->insert_id;

//insert information captured

$query = "SELECT * FROM carttemp WHERE carttemp_sess='$sessid'";
$results = mysqli_query($connect, $query);

//put data in the DB
while ($row = mysqli_fetch_array($results)) {
    extract($row);
    $query4 = "INSERT INTO orderdet(
    orderdet_ordernum, orderdet_qty, orderdet_prodnum)
    
    VALUES (
    '$orderid',
    '$carttemp_quan',
    '$carttemp_prodnum')";

$insert4 = $connect->query($query4);

}

//delete from temp table

$query = "DELETE FROM carttemp WHERE carttemp_sess = '$sessid'";
$delete = $connect->query($query);

//Send Email

$to = "<" . $email .">";
$subject = "Order Confirmation";
$message = "
<html>
<head>
<title>Order Confirmation</title>
</head>
<body>
Your order as submitted<br><br>
Order date: ";
$message .=$today;
$message .= "
    <br>
    Order Number: ";
$message .= $orderid;
$message .= "
    <table width=\"50%\" border=\"0\">
        <tr>
            <td>
                <p>Bill to:<br>";
$message .= $firstname;
$message .= " ";
$message .= $lastname;
$message .= "<br>";
$message .= $add1;
$message .= "<br>";

if ($add2) {
    $message .= $add2 . "<br>";
}

$message .= $city . ", " . $state . " " . $zip;
$message .="</p></td>
    <td>
    <p>Ship to:<br>";
$message .= $shipfirst . " " . $shiplast;
$message .= "<br>";
$message .= $shipadd1 . "<br>";
    if ($shipadd2) {
        $message .= $shipadd2 . "<br>";
    }
$message .= $shipcity . ", " . $shipstate . " " . $shipzip;
$message .= "</p>
    </td>
    </tr>
    </table>
    <hr width=\"250px\" align=\"left\">
    <table cellpadding=\"5\">";

//insert into the message

$query = "SELECT * FROM orderdet WHERE orderdet_ordernum = '$orderid'";
$results = $connect->query($query);


while ($row = mysqli_fetch_array($results)) {
    extract($row);
    $prod = "SELECT * FROM products
        WHERE products_prodnum = '$orderdet_prodnum'";
    
    $prod2 = $connect->query($prod);
    $prod3 = mysqli_fetch_array($results);
    extract($prod3);
    
    $message .= "<tr><td>";
    $message .= $orderdet_qty;
    $message .= "</td>";
    $message .= "<td>";
    $message .= $products_name;
    $message .= "</td>";
    $message .= "<td align=\"right\">";
    $message .= $products_price;
    $message .= "</td>";
    $message .= "<td align=\"right\">";
    
    $extprice = number_format($products_price * orderdet_qty, 2);
    $message .= $extprice;
    $message .= "</td>";
    $message .= "</tr>";

}

    $message .= "<tr>
        <td colspan=\"3\" align=\"right\">
            Your Total before shipping is:
        </td>
        <td align =\"right\">";
    $message .= number_format($total, 2);
    $message .= "
        </td>
        </tr>
        <tr>
        <td colspan=\"3\" align=\"right\">
            Shipping costs:
        </td>        
        <td align=\"right\">";
    $message .= number_format(($total + $shipping), 2);
    $message .= "
        </td>
        </tr>
</table>
</body>
</html>";

$headers .=  "From:<lznaidi@hotmail.com>\r\n";

mail($to, $subject, $message, $headers);

echo "Step 1 - Please Enter Billing and Shipping Information<br>";
echo "Step 2 - Please verify that your order is accurate<br>";
echo "<strong>Step3 - Order Confirmation and Receipt</strong><br><br>";

//echo $message;

?>

i would appreciate if someone can point me to the right direction because i am loosing it with this code....
Thanks for the help




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users