当我通过表单插入值时,我希望日期保存在MySQL数据库中。我不希望用户查看它,但我需要未来函数的日期,所以我可以遍历db中注册的日期。
我是否需要在表单中创建一个隐藏的输入字段,并将其与我的select.php对齐,还是有一种聪明的方法可以做到这一点?
<?php
include('session.php');
include 'dbconfic.inc.php';
$stmt = $mysqli->prepare("INSERT INTO numbertable(numbers) VALUES(?)");
// bind variable: 'd' for digit/tal, 's' for string
$stmt->bind_param('d',intval($_POST["numbervalue"])); // bind
// execute prepared statement
if ($stmt->execute()) { // tjek om udført:
$success = true;
}
// luk statement
$stmt->close();
// luk connection
$mysqli->close();
if($success) {
echo "Insert Succesfull";
} else {
echo "Failed: " . $stmt->error;
}
?>
select.php
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
//include('session.php');
// Selecting Database
include 'dbconfic.inc.php';
$pad_left_values = array(0 => 28, 1 => 10, 2 => 47, 3 => 10, 4 => 47, 5 => 10, 6 => 47, 7 => 10, 8 => 47, 9 => 10, 10 => 42, 11 => 42, 12 => 7, 13 => 42, 14 => 7, 15 => 42, 16 => 7, 17 => 42, 18 => 7, 19 => 7, 20 => 42, 21 => 7, 22 => 42, 23 => 7, 24 => 42, 25 => 7, 26 => 42, 27 => 7, 28 => 42, 29 => 42, 30 => 7, 31 => 42, 32 => 7, 33 => 42, 34 => 7, 35 => 42, 36 => 7);
$colorArr = array(0=>"#029002", 1=>"#ff2700", 2=>"#ffaf32", 3=>"#ff2700", 4=>"#ffaf32", 5=>"#ff2700", 6=>"#ffaf32", 7=>"#ff2700", 8=>"#ffaf32", 9=>"#ff2700", 10=>"#ffaf32", 11=>"#ffaf32", 12=>"#ff2700", 13=>"#ff2700", 13=>"#ffaf32", 14=>"#ff2700", 15=>"#ffaf32", 16=>"#ff2700", 17=>"#ffaf32", 18=>"#ff2700", 19=>"#ff2700", 20=>"#ffaf32", 21=>"#ff2700", 22=>"#ffaf32", 23=>"#ff2700", 24=>"#ffaf32", 25=>"#ff2700", 26=>"#ffaf32", 27=>"#ff2700", 28=>"#ffaf32", 29=>"#ffaf32", 30=>"#ff2700", 31=>"#ffaf32", 32=>"#ff2700", 33=>"#ffaf32", 34=>"#ff2700", 35=>"#ffaf32", 36=>"#ff2700");
// '?' er placeholders for variabler
$stmt = $mysqli->prepare("SELECT numbers FROM numbertable ORDER BY num_id DESC LIMIT 27;");
// execute prepared statement
$stmt->execute();
// gør variabler klar:
$number = null;
$n_id = null;
/* bind result variabler */
$stmt->bind_result($n_id, $number);
/* fetch values for hver row, her kun 1 row dog: */
while ($stmt->fetch()) {
$pad = ($number >= 0 && $number <= 36? $pad_left_values[$number]: $pad_left_values[0]);
$col = ($number >= 0 && $number <= 36? $colorArr[$number]: $colorArr[0]);
echo "<li><div style='padding-left: ".$pad."px; color: ".$col."'>$number</div></li>";
}
// luk statement
$stmt->close();
// luk connection
$mysqli->close();
?>
response.php
if (device.platform == "windows") {
// Get the back button working in WP8.1
WinJS.Application.onbackclick = function () {
onBackKeyDown();
return true; // This line is important, without it the app closes.
}
}
else {
document.addEventListener("backbutton", onBackKeyDown, false);
}
答案 0 :(得分:1)
您必须创建像numdate这样的列作为DATETIME
试试这个:
<?php
include('session.php');
include 'dbconfic.inc.php';
$stmt = $mysqli->prepare("INSERT INTO numbertable(numbers, numdate) VALUES(?, NOW())");
// bind variable: 'd' for digit/tal, 's' for string
$stmt->bind_param('d',intval($_POST["numbervalue"])); // bind
// execute prepared statement
if ($stmt->execute()) { // tjek om udført:
$success = true;
}
// luk statement
$stmt->close();
// luk connection
$mysqli->close();
if($success) {
echo "Insert Succesfull";
} else {
echo "Failed: " . $stmt->error;
}
?>
<强> 更新 强>
您尝试绑定到不存在的内容。
<强> response.php 强>
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
//include('session.php');
// Selecting Database
include 'dbconfic.inc.php';
$pad_left_values = array(0 => 28, 1 => 10, 2 => 47, 3 => 10, 4 => 47, 5 => 10, 6 => 47, 7 => 10, 8 => 47, 9 => 10, 10 => 42, 11 => 42, 12 => 7, 13 => 42, 14 => 7, 15 => 42, 16 => 7, 17 => 42, 18 => 7, 19 => 7, 20 => 42, 21 => 7, 22 => 42, 23 => 7, 24 => 42, 25 => 7, 26 => 42, 27 => 7, 28 => 42, 29 => 42, 30 => 7, 31 => 42, 32 => 7, 33 => 42, 34 => 7, 35 => 42, 36 => 7);
$colorArr = array(0=>"#029002", 1=>"#ff2700", 2=>"#ffaf32", 3=>"#ff2700", 4=>"#ffaf32", 5=>"#ff2700", 6=>"#ffaf32", 7=>"#ff2700", 8=>"#ffaf32", 9=>"#ff2700", 10=>"#ffaf32", 11=>"#ffaf32", 12=>"#ff2700", 13=>"#ff2700", 13=>"#ffaf32", 14=>"#ff2700", 15=>"#ffaf32", 16=>"#ff2700", 17=>"#ffaf32", 18=>"#ff2700", 19=>"#ff2700", 20=>"#ffaf32", 21=>"#ff2700", 22=>"#ffaf32", 23=>"#ff2700", 24=>"#ffaf32", 25=>"#ff2700", 26=>"#ffaf32", 27=>"#ff2700", 28=>"#ffaf32", 29=>"#ffaf32", 30=>"#ff2700", 31=>"#ffaf32", 32=>"#ff2700", 33=>"#ffaf32", 34=>"#ff2700", 35=>"#ffaf32", 36=>"#ff2700");
// '?' er placeholders for variabler
$stmt = $mysqli->prepare("SELECT num_id, numbers FROM numbertable ORDER BY num_id DESC LIMIT 27;");
// execute prepared statement
$stmt->execute();
// gør variabler klar:
$number = null;
$n_id = null;
/* bind result variabler */
$stmt->bind_result($n_id, $number);
/* fetch values for hver row, her kun 1 row dog: */
while ($stmt->fetch()) {
$pad = ($number >= 0 && $number <= 36? $pad_left_values[$number]: $pad_left_values[0]);
$col = ($number >= 0 && $number <= 36? $colorArr[$number]: $colorArr[0]);
echo "<li><div style='padding-left: ".$pad."px; color: ".$col."'>$number</div></li>";
}
// luk statement
$stmt->close();
// luk connection
$mysqli->close();
?>