![](/img/trans.png)
[英]On inserting BLOB data from php to MySQL, I can't see the accurate data type
[英]I can't put data type from html into mysql with php
我正在尝试将 HTML 中的输入数据类型放入 MySQL 数据库,但它不起作用。 当我按下提交按钮时,警报失败。
我在 Bitnami 和 Atom 编辑器中使用 phpMyAdmin 和 Apache。 当我在网络上回显 $reset_btday_input 时,我想要的结果也适合 MySQL DATA 类型(如 2019-01-30),但查询不起作用。 数据库表结构:id varchar(16), pw varchar(16), name varchar(10), btday date 默认NULL
登录.php
<?php
header('Content-Type: text/html; charset=UTF-8');
session_start();
?>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<div class="SignInForm">
<div class="SignInFormContents">
<form action="SignInProgress.php" method="post">
<fieldset class="inputs">
<label>ID</label><input type="text" name="id_input" pattern="[a-zA-z0-9]{6,12}" required><br>
<label>PW</label><input type="password" name="pw_input" pattern="[a-zA-z0-9]{6,12}" required><br>
<label>NAME</label><input type="text" name="name_input" required><br>
<label>BIRTHDAY</label><input type="date" name="btday_input"><br>
</fieldset>
<fieldset class="buttons">
<input type="submit" name="submit_signin" value="SIGN IN">
<input type="reset" name="reset_form" value="RESET">
</fieldset>
</form>
</div>
</div>
</body>
</html>
登录进度.php
<?php
include 'default.php';
$id_input = $_POST['id_input'];
$pw_input = $_POST['pw_input'];
$name_input = $_POST['name_input'];
date_default_timezone_set('Asia/Seoul');
$btday_input = strtotime($_POST['btday_input']);
$reset_btday_input = date('Y-m-d', $btday_input);
echo $reset_btday_input;
$sql = "insert into signin values('$id_input', '$pw_input', '$name_input', '$reset_btday_input')";
$result = $connect->query($sql);
$row = mysqli_fetch_array($result);
if($row){
echo "<script>alert('Success');</script>";
}else{
echo "<script>alert('Fail');</script>";
}
?>
默认.php
<?php
header('Content-Type: text/html; charset=UTF-8');
error_reporting(E_ERROR | E_PARSE);
$connect = mysqli_connect("localhost", "MY_ID", "MY_PASSWORD");
mysqli_select_db($connect, "MY_DB_NAME");
session_start();
?>
当我在 HTML 表单上选择 2019-01-30 时,“echo $reset_btday_input”的结果是网络上的 2019-01-30。 对不起,我的英语句子不太好。 感谢您的帮助! :)
@H.Kwon:首先,您必须在查询中创建值
$sql = "SELECT * FROM `table name` WHERE `something`='{$something}'";
这意味着你想要在数据库中获取什么然后插入你的值
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.