i am trying to get the last id inserted in my sql query, but my varieble returns with NULL
here is my code
$conn->beginTransaction();
try{
$stmt=$conn->prepare("SELECT cn_id FROM food_category WHERE catname= :catname");
$stmt->bindParam(':catname', $_POST['catname'], PDO::PARAM_STR);
$stmt->execute();
$catres= $stmt->fetch(PDO::FETCH_ASSOC);
if(count($catres) > 0 ){
$cn_id= $catres['cn_id'];
}else{
$stmt1= $conn->prepare("INSERT INTO food_category (catname) VALUES (:catname)");
$stmt1->bindParam(':catname', $_POST['catname'], PDO::PARAM_STR);
$stmt1->execute();
$cn_id= $stmt1->lastInsertId();
}
$stmt2=$conn->prepare("SELECT cn_id FROM food_category_en WHERE catname= :catname_en");
$stmt2->bindParam(':catname_en', $_POST['catname_en'], PDO::PARAM_STR);
$stmt2->execute();
$catresen= $stmt2->fetch(PDO::FETCH_ASSOC);
if(count($catresen) > 0 ){
$cn_id_en= $catresen['cn_id'];
}else{
$stmt3= $conn->prepare("INSERT INTO food_category_en (catname) VALUES (:catname_en)");
$stmt3->bindParam(':catname_en', $_POST['catname_en'], PDO::PARAM_STR);
$stmt3->execute();
$cn_id_en= $stmt3->lastInsertId();
}
$stmt4=$conn->prepare("INSERT INTO food_category_main (st_id, cn_id, cn_id_en, catcount) VALUES (:st_id, :cn_id, :cn_id_en, :catcount)");
$stmt4->bindParam(':st_id', $_POST['st_id'], PDO::PARAM_INT);
$stmt4->bindParam(':cn_id', $cn_id, PDO::PARAM_INT);
$stmt4->bindParam(':cn_id_en', $cn_id_en, PDO::PARAM_INT);
$stmt4->bindParam(':catcount', $noc, PDO::PARAM_INT);
$stmt4->execute();
$stmt5=$conn->prepare("UPDATE magazia_main SET noc= :noc WHERE st_id= :st_id");
$stmt5->bindParam(':st_id', $_SESSION['st_id'], PDO::PARAM_INT);
$stmt5->bindParam(':noc', $noc, PDO::PARAM_INT);
$stmt5->execute();
$conn->commit();
header ("Location:dashboard.php?store=".$_SESSION['name']);
exit;
}catch(Exception $e){
//An exception has occured, which means that one of our database queries
//failed.
//Print out the error message.
echo $e->getMessage();
//Rollback the transaction.
$conn->rollBack();
}
I read in the php manual here that if am i using transaction the lastInsertId will return 0. As you see both lastInsertId (1st in stmt1, 2nd in stmt3) are before $conn->commit();, although they return with NULL.
cn_id in food_category and cn_id in food_category_en are both primary keys and AUTO_INCREMENT
i search for some solutions in the internet but none of them seems to fix my problem.
here is a printscreen from php my admin
*** connection to database****
$servername = "localhost";
$username = "root";
$password = "12345";
try {
$conn = new PDO("mysql:host=$servername;dbname=superdb; charset=utf8", $username, $password);
// set the PDO error mode to exception
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
catch(PDOException $e)
{
echo "Connection failed: " . $e->getMessage();
}
?>
Any ideas?
Thanks in advance
Vaggelis
After hours of searching, i didnt find the reason why lastInsertId() returns NULL. Anyway changed my code a little bit and now is working.
I removed the SELECT queries from transaction and i put them in the if statement which checks if the input has value. After that i made two if statements in the pdo transaction to check that if the value cn_id= 0 or cn_id_en= 0.
Here is my code now:
//check is inputs has value
if (empty($_POST['catname'])) {
$errors[] = 'Ξεχάσατε το όνομα της κατηγορίας!';
}else{
$stmt=$conn->prepare("SELECT cn_id FROM food_category WHERE catname= :catname");
$stmt->bindParam(':catname', $_POST['catname'], PDO::PARAM_STR);
$stmt->execute();
$catres= $stmt->fetch(PDO::FETCH_ASSOC);
if(count($catres) > 0 ){
$cn_id= $catres['cn_id'];
}else{
$cn_id=0;
}
}
if (empty($_POST['catname_en'])) {
$errors[] = 'Ξεχάσατε το όνομα της κατηγορίας στα Αγγλικά!';
}else{
$stmt2=$conn->prepare("SELECT cn_id FROM food_category_en WHERE catname= :catname_en");
$stmt2->bindParam(':catname_en', $_POST['catname_en'], PDO::PARAM_STR);
$stmt2->execute();
$catresen= $stmt2->fetch(PDO::FETCH_ASSOC);
if(count($catresen) > 0 ){
$cn_id_en= $catresen['cn_id'];
}else{
$cn_id_en=0;
}
}
if(empty($errors)){
//pdo trasaction
$conn->beginTransaction();
try{
if($cn_id == 0){
$stmt1= $conn->prepare("INSERT INTO food_category (catname) VALUES (:catname)");
$stmt1->bindParam(':catname', $_POST['catname'], PDO::PARAM_STR);
$stmt1->execute();
$cn_id= $conn->lastInsertId();
echo "id1=" . $cn_id;
}
if($cn_id_en == 0){
$stmt3= $conn->prepare("INSERT INTO food_category_en (catname) VALUES (:catname_en)");
$stmt3->bindParam(':catname_en', $_POST['catname_en'], PDO::PARAM_STR);
$stmt3->execute();
$cn_id_en= $conn->lastInsertId();
}
$stmt4=$conn->prepare("INSERT INTO food_category_main (st_id, cn_id, cn_id_en, catcount) VALUES (:st_id, :cn_id, :cn_id_en, :catcount)");
$stmt4->bindParam(':st_id', $_POST['st_id'], PDO::PARAM_INT);
$stmt4->bindParam(':cn_id', $cn_id, PDO::PARAM_INT);
$stmt4->bindParam(':cn_id_en', $cn_id_en, PDO::PARAM_INT);
$stmt4->bindParam(':catcount', $noc, PDO::PARAM_INT);
$stmt4->execute();
$stmt5=$conn->prepare("UPDATE magazia_main SET noc= :noc WHERE st_id= :st_id");
$stmt5->bindParam(':st_id', $_SESSION['st_id'], PDO::PARAM_INT);
$stmt5->bindParam(':noc', $noc, PDO::PARAM_INT);
$stmt5->execute();
$conn->commit();
header ("Location:dashboard.php?store=".$_SESSION['name']);
exit;
}catch(Exception $e){
//An exception has occured, which means that one of our database queries
//failed.
//Print out the error message.
echo $e->getMessage();
//Rollback the transaction.
$conn->rollBack();
}
i wont accept this as an answer for few days, in order to be seen from as many users is possible
Please replace $stmt1, $stmt3 with $conn your code is like this
$conn->beginTransaction();
try{
$stmt=$conn->prepare("SELECT cn_id FROM food_category WHERE catname= :catname");
$stmt->bindParam(':catname', $_POST['catname'], PDO::PARAM_STR);
$stmt->execute();
$catres= $stmt->fetch(PDO::FETCH_ASSOC);
if(count($catres) > 0 ){
$cn_id= $catres['cn_id'];
}else{
$stmt1= $conn->prepare("INSERT INTO food_category (catname) VALUES (:catname)");
$stmt1->bindParam(':catname', $_POST['catname'], PDO::PARAM_STR);
$stmt1->execute();
$cn_id= $conn->lastInsertId();
}
$stmt2=$conn->prepare("SELECT cn_id FROM food_category_en WHERE catname= :catname_en");
$stmt2->bindParam(':catname_en', $_POST['catname_en'], PDO::PARAM_STR);
$stmt2->execute();
$catresen= $stmt2->fetch(PDO::FETCH_ASSOC);
if(count($catresen) > 0 ){
$cn_id_en= $catresen['cn_id'];
}else{
$stmt3= $conn->prepare("INSERT INTO food_category_en (catname) VALUES (:catname_en)");
$stmt3->bindParam(':catname_en', $_POST['catname_en'], PDO::PARAM_STR);
$stmt3->execute();
$cn_id_en= $conn->lastInsertId();
}
$stmt4=$conn->prepare("INSERT INTO food_category_main (st_id, cn_id, cn_id_en, catcount) VALUES (:st_id, :cn_id, :cn_id_en, :catcount)");
$stmt4->bindParam(':st_id', $_POST['st_id'], PDO::PARAM_INT);
$stmt4->bindParam(':cn_id', $cn_id, PDO::PARAM_INT);
$stmt4->bindParam(':cn_id_en', $cn_id_en, PDO::PARAM_INT);
$stmt4->bindParam(':catcount', $noc, PDO::PARAM_INT);
$stmt4->execute();
$stmt5=$conn->prepare("UPDATE magazia_main SET noc= :noc WHERE st_id= :st_id");
$stmt5->bindParam(':st_id', $_SESSION['st_id'], PDO::PARAM_INT);
$stmt5->bindParam(':noc', $noc, PDO::PARAM_INT);
$stmt5->execute();
$conn->commit();
header ("Location:dashboard.php?store=".$_SESSION['name']);
exit;
}catch(Exception $e){
//An exception has occured, which means that one of our database queries
//failed.
//Print out the error message.
echo $e->getMessage();
//Rollback the transaction.
$conn->rollBack();
}
If you get by SQL query then
$stmt1 = $db->query("SELECT LAST_INSERT_ID()");
$lastId = $stmt1->fetchColumn();
Here is the Problem, I want to create a Post-Method for my Webservice. I'm uing the Slim Framework with PHP7 and an SQLite3 Database. I have the following code implemented:
$app->post('/api/generalinformation', function ($request) {
try {
$db = new PDO("sqlite:D:/Schule/notfunk_app/IPNF.db") or die("Cannot open Database");
$query = "insert into nlv_GeneralInformation (SystemID, InformationID, Title, Description, Importance) values (:SystemID, :InformationID, :Title, :Description, :Importance);";
$stmt = $db->prepare($query);
if($stmt === false){
die("prepare() failed");
}
$SystemID = $request->getparsedBody()["SystemID"];
$InformationID = $request->getparsedBody()["InformationID"];
$Title = $request->getparsedBody()["Title"];
$Description = $request->getparsedBody()["Description"];
$Importance = $request->getparsedBody()["Importance"];
$stmt->bindParam(":SystemID", $SystemID, PDO::PARAM_INT);
$stmt->bindParam(":InformationID", $InformationID, PDO::PARAM_INT);
$stmt->bindParam(":Title", $Title, PDO::PARAM_STR);
$stmt->bindParam(":Description", $Description, PDO::PARAM_STR);
$stmt->bindParam(":Importance", $Importance, PDO::PARAM_INT);
$stmt->execute();
$db = null;
} catch (PDOException $e) {
echo $e->getMessage();
}
});
But the prepare() funktion always returns me false. I've testet the query and it works.
i am using php slim framework 3
my function is inserting null instead of data
function addstud(Request $request, Response $response)
{
$stud = $request->getParsedBody();
$sql = "INSERT INTO students (`name`, `username`, `password`) VALUES (':name', ':username', ':password')";
try {
$db = GetDatabase();
$stmt = $db->prepare($sql);
$stmt->bindParam("name", $stud->name);
$stmt->bindParam("username", $stud->username);
$stmt->bindParam("password", $stud->password);
$stmt->execute();
$stud->id = $db->lastInsertId();
$db = null;
echo json_encode($stud);
} catch(PDOException $e) {
echo '{"error":{"text":'. $e->getMessage() .'}}';
}
}
can any one help me out ?
You're binding parameters incorrectly: you forgot colon. So, instead of
$stmt->bindParam("name", $stud->name);
$stmt->bindParam("username", $stud->username);
$stmt->bindParam("password", $stud->password);
You should do
$stmt->bindParam(":name", $stud->name);
$stmt->bindParam(":username", $stud->username);
$stmt->bindParam(":password", $stud->password);
I'm newbie with pdo. Here i'm trying to insert the datas into database using this below coding. But, i cannot able to insert the datas into database. I'm getting this following error
Fatal error: Call to a member function prepare() on a non-object
I searched on SO and internet about this error. Some people says add global $conn; at the top of your code. I added these code but i'm getting same error. Anyone tell me what should i do if i want to clear this error?
Config.php
<?php
$user = "root";
$password = "password";
try
{
$conn = new PDO('mysql:host=localhost;dbname=evouchers', $user, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
catch(PDOException $e)
{
'DATABASE CONNECTION ERROR' .$e->getMessage();
}
?>
**Database.php**
<?php
session_start();
include('config.php');
if(isset($_POST['submit_val']))
{
$cmeal = $_POST['meal'];
try
{
$stmt = $conn->prepare("INSERT INTO ebmealplans ( MealPlanName, CreatedOn ) VALUES ( :cmeal, NOW() )");
$conn->errorInfo();
$stmt->bindParam(':cmeal', $cmeal, PDO::PARAM_STR);
$stmt->execute();
}
catch(PDOException $e)
{
'Query failed to insert into database ' .$e->getMessage();
}
$croom = $_POST['room'];
$ref_key = $conn->lastInsertId();
try
{
$stmt = $conn->prepare("INSERT INTO ebroomtypes ( RoomTypeName, CreatedOn ) VALUES ( :croom, NOW() )");
$conn->errorInfo();
$stmt->bindParam(':croom', $croom, PDO::PARAM_STR);
$stmt->execute();
}
catch(PDOException $e)
{
'Query failed to insert into database ' .$e->getMessage();
}
<*************** UPDATED CODES ***************>
$creference = $_POST['reference'];
$crefdate = $_POST['refdate'];
$ccin = $_POST['cin'];
$cout = $_POST['out'];
$cgname = $_POST['gname'];
$ctotaladults = $_POST['totaladults'];
$cchildrens = $_POST['childrens'];
$cinfants = $_POST['infants'];
$cgphone = $_POST['gphone'];
$cgemail = $_POST['gemail'];
$cgfax = $_POST['gfax'];
$cgaddress1 = $_POST['gaddress1'];
$cgaddress2 = $_POST['gaddress2'];
$cregion = $_POST['region'];
$ccity = $_POST['city'];
$cstate = $_POST['city_state'];
$ccountry = $_POST['country'];
$ccurrency = $_POST['currency'];
$ccurrencyto = $_POST['tocurrency'];
$camount = $_POST['camount'];
$ccurrencyvalue = $_POST['currencyvalue'];
$voucher_fk = $conn->lastInsertId();
try
{
$stmt = $conn->prepare("INSERT INTO ebvouchers ( VoucherReference, BookingDate, CheckIndate, CheckOutDate, MealPlanID_Fk, RoomTypeID_Fk, GuestName, TotalAdults, Childrens, Infants, GuestPhone, GuestEmail, GuestFax, GuestAddressLine1, GuestAddressLine2, GuestRegion, GuestCity, GuestState, GuestCountry, GuestCurrency, GuestCurrencyTo, CurrencyAmount, GuestCurrencyValue, VoucherCreatedOn ) VALUES ( :reference, :refdate, :ccin, :cout, :r_key, :r_key, :gname, :totaladults, :childrens, :infants, :gphone, :gemail, :gfax, :gaddress1, :gaddress2, :gregion, :city, :state, :country, :currency, :currencyto, :amount, :currencyvalue, NOW() )");
$conn->errorInfo();
$stmt->bindParam(':reference', $creference, PDO::PARAM_STR);
$stmt->bindParam(':refdate', $crefdate, PDO::PARAM_STR);
$stmt->bindParam(':ccin', $ccin, PDO::PARAM_STR);
$stmt->bindParam(':cout', $cout, PDO::PARAM_STR);
$stmt->bindParam(':r_key', $ref_key, PDO::PARAM_STR);
$stmt->bindParam(':r_key', $ref_key, PDO::PARAM_STR);
$stmt->bindParam(':gname', $cgname, PDO::PARAM_STR);
$stmt->bindParam(':totaladults', $ctotaladults, PDO::PARAM_STR);
$stmt->bindParam(':childrens', $cchildrens, PDO::PARAM_STR);
$stmt->bindParam(':infants', $cinfants, PDO::PARAM_STR);
$stmt->bindParam(':gphone', $cgphone, PDO::PARAM_STR);
$stmt->bindParam(':gemail', $cgemail, PDO::PARAM_STR);
$stmt->bindParam(':gfax', $cgfax, PDO::PARAM_STR);
$stmt->bindParam(':gaddress1', $cgaddress1, PDO::PARAM_STR);
$stmt->bindParam(':gaddress2', $cgaddress2, PDO::PARAM_STR);
$stmt->bindParam(':gregion', $cregion, PDO::PARAM_STR);
$stmt->bindParam(':city', $ccity, PDO::PARAM_STR);
$stmt->bindParam(':state', $cstate, PDO::PARAM_STR);
$stmt->bindParam(':country', $ccountry, PDO::PARAM_STR);
$stmt->bindParam(':currency', $ccurrency, PDO::PARAM_STR);
$stmt->bindParam(':currencyto', $ccurrencyto, PDO::PARAM_STR);
$stmt->bindParam(':amount', $camount, PDO::PARAM_STR);
$stmt->bindParam(':currencyvalue', $ccurrencyvalue, PDO::PARAM_STR);
$stmt->execute();
}
catch(PDOException $e)
{
'Query failed to insert into database ' .$e->getMessage();
}
<*************** UPDATED CODES ***************>
foreach ( $_POST['slno'] as $key=>$slno )
{
$date = $_POST['date'][$key];
$particulars = $_POST['particulars'][$key];
$noofnights = $_POST['noofnights'][$key];
$rate = $_POST['rate'][$key];
$price = $_POST['price'][$key];
$tax = $_POST['tax'][$key];
$nettotal = $_POST['nettotal'];
$totalamount = $_POST['totalamount'];
$finaltotal = $_POST['finaltotal'];
$c_date = $date;
$c_slno = $slno;
$c_particulars = $particulars;
$c_noofnights = $noofnights;
$c_rate = $rate;
$c_price = $price;
$c_tax = $tax;
$c_nettotal = $nettotal;
$c_totalamount = $totalamount;
$c_finaltotal = $finaltotal;
try
{
$stmt = $conn->prepare("INSERT INTO ebvouchertariffs ( TariffSlNo, TariffDate, TariffParticulars, NoOfNights, TariffRate, TariffPrice, TariffTax, TariffNetTotal, TariffAddTotal, TariffFinalTotal, VoucherID_Fk, CreatedOn ) VALUES ( :c_slno, :c_date, :c_particulars, :c_noofnights, :c_rate, :c_price, :c_tax, :c_nettotal, :c_totalamount, :c_finaltotal, :voucher_fk, NOW() )");
$conn->errorInfo();
$stmt->bindParam(':c_slno', $c_slno, PDO::PARAM_STR);
$stmt->bindParam(':c_date', $c_date, PDO::PARAM_STR);
$stmt->bindParam(':c_particulars', $c_particulars, PDO::PARAM_STR);
$stmt->bindParam(':c_noofnights', $c_noofnights, PDO::PARAM_STR);
$stmt->bindParam(':c_rate', $c_rate, PDO::PARAM_STR);
$stmt->bindParam(':c_price', $c_price, PDO::PARAM_STR);
$stmt->bindParam(':c_tax', $c_tax, PDO::PARAM_STR);
$stmt->bindParam(':c_nettotal', $c_nettotal, PDO::PARAM_STR);
$stmt->bindParam(':c_totalamount', $c_totalamount, PDO::PARAM_STR);
$stmt->bindParam(':c_finaltotal', $c_finaltotal, PDO::PARAM_STR);
$stmt->bindParam(':voucher_fk', $voucher_fk, PDO::PARAM_STR);
$stmt->execute();
}
catch(PDOException $e)
{
'Query failed to insert into database ' .$e->getMessage();
}
$conn = null;
}
}
?>
You did not print your exception. If you have any exception you will not get it. and i think problem in your $conn= null;
$conn = null; this line makes your connection object invalid and after executing this line you have invalid pdo object.for this you have got this error in loop. it should execute all other query before this line is executed. just remove this line. and print your exception message like this:
Try this:
<?php
session_start();
include('config.php');
if(isset($_POST['submit_val']))
{
$cmeal = $_POST['meal'];
try
{
$stmt = $conn->prepare("INSERT INTO ebmealplans ( MealPlanName, CreatedOn ) VALUES ( :cmeal, NOW() )");
$conn->errorInfo();
$stmt->bindParam(':cmeal', $cmeal, PDO::PARAM_STR);
$stmt->execute();
}
catch(PDOException $e)
{
die('Query failed to insert into database ' .$e->getMessage());
}
$croom = $_POST['room'];
$ref_key = $conn->lastInsertId();
try
{
$stmt = $conn->prepare("INSERT INTO ebroomtypes ( RoomTypeName, CreatedOn ) VALUES ( :croom, NOW() )");
$conn->errorInfo();
$stmt->bindParam(':croom', $croom, PDO::PARAM_STR);
$stmt->execute();
}
catch(PDOException $e)
{
die( 'Query failed to insert into database ' .$e->getMessage());
}
foreach ( $_POST['slno'] as $key=>$slno )
{
$date = $_POST['date'][$key];
$particulars = $_POST['particulars'][$key];
$noofnights = $_POST['noofnights'][$key];
$rate = $_POST['rate'][$key];
$price = $_POST['price'][$key];
$tax = $_POST['tax'][$key];
$nettotal = $_POST['nettotal'];
$totalamount = $_POST['totalamount'];
$finaltotal = $_POST['finaltotal'];
$c_date = $date;
$c_slno = $slno;
$c_particulars = $particulars;
$c_noofnights = $noofnights;
$c_rate = $rate;
$c_price = $price;
$c_tax = $tax;
$c_nettotal = $nettotal;
$c_totalamount = $totalamount;
$c_finaltotal = $finaltotal;
try
{
$stmt = $conn->prepare("INSERT INTO ebvouchertariffs ( TariffSlNo, TariffDate, TariffParticulars, NoOfNights, TariffRate, TariffPrice, TariffTax, TariffNetTotal, TariffAddTotal, TariffFinalTotal, VoucherID_Fk, CreatedOn ) VALUES ( :c_slno, :c_date, :c_particulars, :c_noofnights, :c_rate, :c_price, :c_tax, :c_nettotal, :c_totalamount, :c_finaltotal, :voucher_fk, NOW() )");
$conn->errorInfo();
$stmt->bindParam(':c_slno', $c_slno, PDO::PARAM_STR);
$stmt->bindParam(':c_date', $c_date, PDO::PARAM_STR);
$stmt->bindParam(':c_particulars', $c_particulars, PDO::PARAM_STR);
$stmt->bindParam(':c_noofnights', $c_noofnights, PDO::PARAM_STR);
$stmt->bindParam(':c_rate', $c_rate, PDO::PARAM_STR);
$stmt->bindParam(':c_price', $c_price, PDO::PARAM_STR);
$stmt->bindParam(':c_tax', $c_tax, PDO::PARAM_STR);
$stmt->bindParam(':c_nettotal', $c_nettotal, PDO::PARAM_STR);
$stmt->bindParam(':c_totalamount', $c_totalamount, PDO::PARAM_STR);
$stmt->bindParam(':c_finaltotal', $c_finaltotal, PDO::PARAM_STR);
$stmt->bindParam(':voucher_fk', $voucher_fk, PDO::PARAM_STR);
$stmt->execute();
}
catch(PDOException $e)
{
die('Query failed to insert into database ' .$e->getMessage());
}
//$conn = null;
}
}
?>
I've been stuck on this on for hours. I keep getting this error code
SQLSTATE[HY000]: General error: 25 bind or column index out of range
Tried everything I could find.
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $db->prepare('insert into rentals(title, pid, uid, address, description, amenities, manager_name, bedrooms, sale_price, property_type, manager_phone, manager_email)
values(:title, :pid, :uid, :address, :description, :amenities, :manager_name, :bedrooms, :sale_price, :property_type, :manager_phone, :manager_email)');
$stmt->bindParam(':title', $_POST['title']);
echo $_POST['title'].'<br/>';
$stmt->bindParam(':pid', $pid);
echo $pid.'<br/>';
$stmt->bindParam(':uid', $uid);
echo$uid.'<br/>';
$stmt->bindParam(':address', $_POST['street-address']);
echo $_POST['street-address'].'<br/>';
$stmt->bindParam(':description', $_POST['description']);
echo $_POST['description'].'<br/>';
$arr= array($_POST['smoking'], $_POST['children'], $_POST['refridgerator'],
$_POST['internet'], $_POST['utils'], $_POST['pool'], $_POST['laundry'],
$_POST['microwave'], $_POST['stove'], $_POST['cable'],
$_POST['cleaning'], $_POST['ac']);
$arr = array_filter($arr, 'strlen');
$amenities = join(':|:', $arr);
$stmt->bindParam(':amenities', $amenities);
echo $amenities.'<br/>';
$stmt->bindParam(':manager_name', $_POST['manager']);
echo $_POST['manager'].'<br/>';
$stmt->bindParam(':bedrooms', $_POST['bedrooms']);
echo $_POST['bedrooms'].'<br/>';
$stmt->bindParam(':sale_price', $_POST['prices']);
echo $_POST['prices'].'</br>';
$stmt->bindParam(':property_type', $_POST['property_type']);
echo $_POST['property_type'].'<br/>';
$stmt->bindParam(':manager-phone', $_POST['manager-phone']);
echo $_POST['manager-phone'].'<br/>';
$stmt->bindParam('manager_email', $_POST['manager-email']);
echo $_POST['manager-email'].'<br/>';
$stmt->execute();
}catch(Exception $e){
echo $e->getMessage();
}
unset($db);