What does this mean: Object Id #2

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
traxy
Forum Newbie
Posts: 9
Joined: Thu Mar 26, 2009 11:34 pm

What does this mean: Object Id #2

Post by traxy »

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.

Code: Select all

 
<?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.
Last edited by Benjamin on Sat May 02, 2009 3:48 am, edited 1 time in total.
Reason: Changed code type from text to php.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: What does this mean: Object Id #2

Post by Benjamin »

Your usage of mysqli_query is not correct. Please reference the example below, taken from the manual:

http://us3.php.net/manual/en/mysqli.query.php

Code: Select all

 
<?php
$mysqli = new mysqli("localhost", "my_user", "my_password", "world");
 
/* check connection */
if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
}
 
/* Create table doesn't return a resultset */
if ($mysqli->query("CREATE TEMPORARY TABLE myCity LIKE City") === TRUE) {
    printf("Table myCity successfully created.\n");
}
 
/* Select queries return a resultset */
if ($result = $mysqli->query("SELECT Name FROM City LIMIT 10")) {
    printf("Select returned %d rows.\n", $result->num_rows);
 
    /* free result set */
    $result->close();
}
 
/* If we have to retrieve large amount of data we use MYSQLI_USE_RESULT */
if ($result = $mysqli->query("SELECT * FROM City", MYSQLI_USE_RESULT)) {
 
    /* Note, that we can't execute any functions which interact with the
       server until result set was closed. All calls will return an
       'out of sync' error */
    if (!$mysqli->query("SET @a:='this will not work'")) {
        printf("Error: %s\n", $mysqli->error);
    }
    $result->close();
}
 
$mysqli->close();
?>
 
Post Reply