我的错误是什么
<?php
$conn = mysqli_connect("localhost","root","");
if(!$conn)
{
die('Server not Connected : '.mysqli_error());
}
if(!mysqli_select_db($conn,'myphp'))
{
echo "Database not connected";
}
if(isset($_POST['submit']))
// if(isset($_POST["f_name"]) && isset($_POST["s_name"]) && isset($_POST["age"]) && isset($_POST["email_id"]) && isset($_POST["dob"]))
{
$first_name = $_POST["f_name"];
$second_name = $_POST["s_name"];
$agee = $_POST["age"];
$email_ids = $_POST["email_id"];
$dobs = $_POST["dob"];
$sql = "INSERT INTO crud (First Name, Last Name, Age, Email Id, DOB) VALUES ('".$_POST["f_name"]."','".$_POST["s_name"]."','".$_POST["age"]."','".$_POST["email_id"]."','".$_POST["dob"]."')";
}
if(!mysqli_query($conn,$sql))
{
echo "Not Insert sucessfully";
}
else
{
echo "Successfully Import th Data to Database";
}
?>
<html>
<head>
<title>My CRUD Model</title>
</head>
<body>
<form method="POST" action="">
First Name : <input type="text" name="f_name"/><br>
Second Name : <input type="text" name="s_name"/><br>
Age : <input type="number" name="age"/><br>
Email Id : <input type="email" name="email_id"/><br>
DOB : <input type="date" name="dob"/><br>
<input type="submit" name="submit" value="submit">
</form>
</body>
</html>
答案 0 :(得分:1)
请在文件名下面用数据库替换一个: 如果无法正常工作,请发布有关您的桌子屏幕截图的问题
INSERT INTO crud(名字,姓氏,年龄,email_id,dob)
$sql = " INSERT INTO crud (first_name, last_name, age, email_id, dob) VALUES ('".$_POST["f_name"]."','".$_POST["s_name"]."','".$_POST["age"]."','".$_POST["email_id"]."','".$_POST["dob"]."')";
答案 1 :(得分:0)
用以下代码替换php代码并检查。
<?php
$conn = mysqli_connect("localhost","root","","myphp");
if(!$conn)
{
die('Database not connected : '.mysqli_error());
}
if(isset($_POST['submit']))
// if(isset($_POST["f_name"]) && isset($_POST["s_name"]) && isset($_POST["age"]) && isset($_POST["email_id"]) && isset($_POST["dob"]))
{
$first_name = $_POST["f_name"];
$second_name = $_POST["s_name"];
$agee = $_POST["age"];
$email_ids = $_POST["email_id"];
$dobs = $_POST["dob"];
$sql = "INSERT INTO crud (first_name, last_name, age, email_id, dob) VALUES ('".$_POST["f_name"]."','".$_POST["s_name"]."','".$_POST["age"]."','".$_POST["email_id"]."','".$_POST["dob"]."')";
if(!mysqli_query($conn,$sql))
{
echo "Not Insert sucessfully";
}
else
{
echo "Successfully Import th Data to Database";
}
}
?>