pdo - Blank Page with PHP script -
im trying input form , delete table data display the updated table blank page don't know problem appericiated here's code:
<html> <body> <?php $mysqli = new mysqli("xxxxx", "xxxxxx", "xxxxx", "xxxxxx"); /* check connection */ if (mysqli_connect_errno()) { printf("connect failed: %s\n", mysqli_connect_error()); exit(); } //----------------------------------------------------------------------------------// $name = $_post['car_id']; if ($stmt = $mysqli->prepare("delete cars name=?")) { // bind variable parameter string. $stmt->bind_param("s", $name); // execute statement. $stmt->execute(); echo "deleted data successfully\n"; // close prepared statement. $mysqli->setattribute(pdo::attr_errmode, pdo::errmode_exception); $result = $db->prepare("select id, doors, transmission, fuel_type, engine_size, total cars"); $result->execute(); while ($row = $result->fetch(pdo::fetch_assoc)){ $doors=$row["doors"]; $engine=$row["engine_size"]; $total=$row["total"]; $trans=$row["transmission"]; } ?> <table> <tr> <td><?php echo $doors; ?></td> <td><?php echo $engine; ?></td> <td><?php echo $total; ?></td> <td><?php echo $trans; ?></td> </tr> <?php } ?> </table> </body> </html>
you're mixing mysqli
pdo
$mysqli->setattribute(pdo::attr_errmode, pdo::errmode_exception);
and you're passing $db
(theoretically) should $mysqli
$result = $db->prepare("select id, doors, transmission, fuel_type, engine_size, total, date_initiated, age, partno, qty, description, loc cars");
where theoretically, should be
$result = $mysqli->prepare("select id, doors, transmission, fuel_type, engine_size, total, date_initiated, age, partno, qty, description, loc cars");
since db connection is:
$mysqli = new mysqli("xxxxx", "xxxxxx", "xxxxx", "xxxxxx");
however, db connection should resemble:
$mysql_hostname = 'xxx'; $mysql_username = 'xxx'; $mysql_password = 'xxx'; $mysql_dbname = 'xxx'; $db = new pdo("mysql:host=$mysql_hostname;dbname=$mysql_dbname", $mysql_username, $mysql_password); $db->setattribute(pdo::attr_errmode, pdo::errmode_exception);
you can't this:
$stmt->bind_param("s", $name);
you're using pdo remember? (or you?) take pick, mysqli
or pdo?
you want do:
// $stmt = $db->prepare("delete cars name=:value"); if ($stmt = $db->prepare("delete cars name=:value")) { // bind variables statement $stmt->bindparam(':value', $name); ... }
Comments
Post a Comment