Jump to content

What does this mean: Object Id #2


traxy

Recommended Posts

Hey Guys,

 

    I am having trouble, I am working on an assignment is basically an online store that sells CDs. Now I am trying to add items to the Cart but getting is weird error "Object Id #2", see below for the code and yes I know its very messy code at the moment but im just testing with it.

 

<?php

$DBConnect=@mysqli_connect("localhost", "username", "password", "database")
    Or die("<p>Unable to connect to the database server.</p>" . "<p>Error code " . mysqli_connect_errno($DBConnect) . ":" . mysqli_connect_error($DBConnect)) . "</p>";

$TableName="cart";
$CdId = "$_GET[cdid]";
$CdNamestring = "SELECT cd_name FROM CDs WHERE cd_id='$CdId'";
$CdName = mysqli_query($DBConnect, $CdNamestring);
$ItemQtystring = "SELECT item_qty FROM cart WHERE cd_id='$CdId'";
$ItemQty = mysqli_query($DBConnect, $ItemQtystring);
$TotalQty = $ItemQty + 1;
$Pricestring = "SELECT cd_price FROM CDs WHERE cd_id='$CdId'";
$Price = mysqli_query($DBConnect, $Pricestring);
$CurrentTotalPricestring = "SELECT total_price FROM cart WHERE cd_id='$CdId'";
$CurrentTotalPrice = mysqli_query($DBConnect, $CurrentTotalPricestring);
$TotalPrice = $Price + $CurrentTotalPrice;

echo "Table: '$TableName' cd_id: '$CdId' CD Name: $CdName ItemQty: '$ItemQty' TotalQty: '$TotalQty' Price: '$Price' Current Total: '$CurrentTotalPrice' TOTAL:'$TotalPrice'";

$SQLstring = "INSERT INTO $TableName VALUES ('','','$CdName','$TotalQty','$TotalPrice')";
$QueryResult=mysqli_query($DBConnect, $SQLstring)
Or die("<p>Unable to execute the query.</p>" . "<p>Error code " . mysqli_connect_errno($DBConnect) . ":" . mysqli_connect_error($DBConnect)) . "</p>" .
'<a href="admin.html">Return to Delete.php page</a>';
echo "<p>Successfully Added to Cart</p>";	
echo '<a href="main.php">Return CD Selection</a>';
mysqli_close($DBConnect);  

?>

 

Im echoing all the variables to the screen to see what they are and this is the output:

 

Table: 'cart' cd_id: '2' CD Name: Object id #2 ItemQty: 'Object id #3' TotalQty: '2' Price: 'Object id #4' Current Total: 'Object id #5' TOTAL:'2'

 

 

Please let me know if you need more information.

Link to comment
Share on other sites

OK... you got it all wrong

 

MySQLi is used like this:

 

$qry = "SELECT cd_name, item_qty, cd_price FROM CDs WHERE cd_id='$CdId'";
$result = mysqli_query($DBConnect, $Pricestring);
$row = mysqli_fetch_assoc($result);

var_dump($row); //this will show an array with data


Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.