Reputation: 91
I am having the hardest time of my life trying to figure out how to get this code to work. Basically, I have an html script getting values from a user, and I am taking those values and storing them in a database. I have procedures to do the storing, and those work... I am having a problem extracting values from a procedure for later use:
$addressID = "CALL get_addressID('".$_POST['street_address']."', '".$_POST['city']."', '".$_POST['state']."', '".$_POST['zip']."', '".$_POST['country']."')";
$creditID = "CALL get_creditID('".$_POST["name_on_card"]."', '".$_POST["card_num"]."','".$_POST["exp_date"]."','".$_POST["sec_code"]."', '".$_POST["billing_st_address"]."', '".$_POST["billing_city"]."', '".$_POST["billing_state"]."','".$_POST["billing_zip"]."','".$_POST["billing_country"]."')";
$obj = mysqli_query($conn, $creditID);
$SSS = mysqli_query($conn, $addressID);
(line 100) $sql = "CALL add_customer('".$_POST["first_name"]."', '".$_POST["last_name"]."', '".$obj."', '".$SSS."', '".$_POST["email"]."')";
if ($conn->query($sql) === TRUE) {
echo "User data info stored successfully\n";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
I would like to be able to use $obj and $SSS for this part so that I can create a user with them. I am getting the following error: "Catchable fatal error: Object of class mysqli_result could not be converted to string in C:\wamp64\www\project\CustomerAttempt.php on line 100"
The procedures i am running are as follows:
SELECT address_id FROM address where street_address = st_address and City =
Fcity AND state = Fstate and postal_code = fzip and country = fcountry
and:
SELECT card_ID from credit_card WHERE Cardholders_Name = name_on_card AND Card_number = card_num AND Expiration_date = exp_date AND Security_code = sec_code AND Billing_Street_Address = billing_st_address AND Billing_City = billing_city_f AND Billing_State = billing_state_f AND Billing_Postal_Code = billing_zip AND Billing_Country = billing_country_f
I have no idea what to do, and am new to php, and mysql. Any help would be appreciated.
I am connected to my database with mysqli_connect using $conn as the variable for that.
Upvotes: 0
Views: 46
Reputation: 26
Well, your understanding of mysqli_query is just a bit off. This is what the php documentation states that mysqli_query will return.
"Returns FALSE on failure. For successful SELECT, SHOW, DESCRIBE or EXPLAIN queries mysqli_query() will return a mysqli_result object. For other successful queries mysqli_query() will return TRUE."
In other words, your
$obj = mysqli_query($conn, $creditID);
line will return a mysql result object, not a string that you can append. In order to get the string for that, you can use
$object = $obj->fetch_object();
$string = $object->columnName;
columnName would have to be the name of the column that stores the value you are wanting to extract.
Upvotes: 1