Hi! Could we please enable some services and cookies to improve your experience and our website?
Online Sandbox for SQL and PHP: Write, Run, Test, and Share SQL Queries and PHP Code
<?php
use Carbon\Carbon;
$now = Carbon::now()->format('d/m/Y');
printf("Today is %s\nCurrent PHP version: %s \n\n", $now, phpversion());
$query = "SELECT VERSION() as version;";
// get DB version using PDO
$stmt = $pdo->prepare($query);
$stmt->execute();
$row = $stmt->fetch(PDO::FETCH_ASSOC);
printf('DB version (PDO): %s ' . PHP_EOL, $row['version']);
// Run query using mysqli
$result = $mysqli->query($query);
$version = $result->fetch_object();
printf('DB version (mysqli): %s ' . PHP_EOL, $version->version);
<form action="process_form.php" method="post">
<fieldset>
<legend>Birth date:</legend>
<select name="birth-month" id="birth-month">
<option value="0">--Select Month--</option>
<?php
for ($i=1; $i<=12; $i++) {
echo "<option value='$i'>" . $months[$i-1] . "</option>";
}
?>
</select>
<input name="birth-day" type="number" min="1" max="31" placeholder="day">
<input name="birth-year" type="number" placeholder="year">
</fieldset>
<fieldset>
<legend>Hire date:</legend>
<select name="hire-month">
<option value="0">--Select Month--</option>
<?php
for ($i=1; $i<=12; $i++) {
echo "<option value='$i'>" . $months[$i-1] . "</option>";
}
?>
</select>
<input name="hire-day" type="number" min="1" max="31" placeholder="day">
<input name="hire-year" type="number" placeholder="year">
</fieldset>
<input type="submit" value="Submit">
</form>
<?php
// Capture form data
$birth_month = $_POST['birth-month'];
$birth_day = $_POST['birth-day'];
$birth_year = $_POST['birth-year'];
$hire_month = $_POST['hire-month'];
$hire_day = $_POST['hire-day'];
$hire_year = $_POST['hire-year'];
// Validate and sanitize input
$birth_month = filter_var($birth_month, FILTER_SANITIZE_NUMBER_INT);
$birth_day = filter_var($birth_day, FILTER_SANITIZE_NUMBER_INT);
$birth_year = filter_var($birth_year, FILTER_SANITIZE_NUMBER_INT);
$hire_month = filter_var($hire_month, FILTER_SANITIZE_NUMBER_INT);
$hire_day = filter_var($hire_day, FILTER_SANITIZE_NUMBER_INT);
$hire_year = filter_var($hire_year, FILTER_SANITIZE_NUMBER_INT);
// Database connection
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Select using Laravel
$version = $db::select($query);
printf('DB version (Laravel Query Builder): %s ' . PHP_EOL, $version[0]->version);