insert.php
<html>
<head>
<title>Insert</title>
</head>
<body>
<from action="insert_post.php" method="post">
<label>Name</label>
<input type="text" id="name" name="name" >
<label>Email</label>
<input type="text" id="email" name="email">
<button type="submit" id="button">SAVE</button>
</form>
</body>
</html>
insert数据库
insert_post.php
<?php
$servername="localhost:3305";
$username="root";
$password="1234";
$dbname="dj";
//create connection
$conn= mysqli_connect($servername,$username,$password,$dbname);
if (!$conn){
die("Connection failed:".mysqli_connect_error());
}
echo "Connected successfully";
$name=$_POST['name'];
$email=$_POST['email'];
$sql="insert into `insert` (name,email) VALUES ($name,$email)"; // ==注意这里!==
$query=mysqli_query($conn,$sql);
if($query){
echo"okay!";
}else{
echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}
Error:
解决方案:
问题出现在insert_post.php 里头中的
$sql="insert into `insert` (name,email) VALUES ($name,$email)"; // ==注意这里!==
改成:
$sql="insert into `insert` (name,email) VALUES ('$name','$email')";
Unknown column ’ ’ in 'field list’
因数据name 和 email 都设定为 varchar 必须加 ’ $name ’