Answer the question
In order to leave comments, you need to log in
How to infer from a database using PDO?
I am accessing the database using PDO, I want to display the lines I need on the page, but for some reason it does not work out. Tell me what's the problem?
The HTML code fetches 2 dates, starting with the smaller one and going up to the larger one, the database displays all the records in that span.
<form method = "post">
<input type = "date" name = "date-begin">
<input type = "date" name = "date-end">
<input type = "submit" name = "show-table">
</form>
if(isset($_POST['show-table'])) {
$host = '';
$dbname = '';
$user = '';
$pass = '';
// Подкючение
try {
$DBH = new PDO("mysql:host=$host;dbname=$dbname", $user, $pass);
$DBH->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
}
catch(PDOException $e) {
echo $e->getMessage();
}
$DBH->exec("set names utf8");
$date_begin = $_POST["date_begin"];
$date_end = $_POST["date_end"];
echo $date_begin;
echo $date_end;
$STH = $DBH->prepare("SELECT * FROM payments_tricolor_office WHERE (date >= ? and date <= ?);");
$STH->bindParam(1, $date_begin);
$STH->bindParam(2, $date_end);
$STH->execute();
$data = $STH->fetch();
while ($data = $STH->fetch()) {
echo $data;
}
//Отключение
$STH - null;
$DBH = null;
}
Answer the question
In order to leave comments, you need to log in
ini_set('error_reporting',E_ALL);
ini_set('display_errors', 1);
var_dump($_POST);
var_dump($data);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question