button - PHP Delete products / ID -
so have this:
echo " <form action='users/delete.php' method='post'> <input type='hidden' name='productid' value='".$row->productid."' /> <input type='submit' value='delete' /> </form> ";
this comes under every item on webshop:
that works, whenever press button table not being deleted, delete.php
<?php define('_host_name_', 'localhost'); define('_user_name_', 'root'); define('_db_password', '#####'); define('_database_name_', 'ws_webshop'); //pdo database connection try { $databaseconnection = new pdo('mysql:host='._host_name_.';dbname='._database_name_, _user_name_, _db_password); $databaseconnection->setattribute(pdo::attr_errmode, pdo::errmode_exception); } catch(pdoexception $e) { echo 'error: ' . $e->getmessage(); } // create pdo instance; assign $db variable $sql = "delete `tbl_products` `productid` = :productid limit 1"; $smt = $databaseconnection->prepare($sql); $smt->bindparam(':productid', $_post['productid'], pdo::param_int); $smt->execute(); header('location: ../webshop.php');
but doesnt remove it, see problem? thanks!
your $row
usage object, have array. either change fetch to:
->fetch(pdo::fetch_obj);
-http://php.net/manual/en/pdostatement.fetch.php
or change usage to:
echo " <form action='users/delete.php' method='post'> <input type='hidden' name='productid' value='".$row['productid'] . "' /> <input type='submit' value='delete' /> </form> ";
Comments
Post a Comment