HTML
<form method="post" action="">
<input type="text" name="f_name" placeholder="الاسم الأول" required/><br>
<input type="text" name="l_name" placeholder="اللقب" required/><br>
<input type="text" name="email" placeholder="البريد" required/><br>
<input type="text" name="birth" placeholder="تاريخ الميلاد" required/><br>
<input type="text" name="city" placeholder="المدينة" required/><br>
<select name="location">
<option value="almnshia">almnshia</option>
<option value="aljadid">aljadid</option>
<option value="algurda">algurda</option>
<option value="algurda">altanwya</option>
</select>
<input type="text" name="user_name" placeholder="اسم المستخدم" required/><br>
<input type="text" name="desc" placeholder="الوصفة" required/><br>
<select name="disab">
<option value="yes">yes</option>
<option value="no">no</option>
</select><br>
<input type="password" name="pass" placeholder="كلمة السر" required/><br>
<input type="submit" name="done" value="signup"/>
</form>
PHP插入
<?php
$servername="localhost";
$username="root";
$password="";
$database="exam";
//create connection
$conn=new mysqli($servername , $username , $password , $database);
if($conn->connect_error){
die("connection failed:".$conn->connect_error);
}
else {
echo "connected successfully";
}
if(isset($_POST['done'])){
$f_name=$_POST['f_name'];
$l_name=$_POST['l_name'];
$email=$_POST['email'];
$birth=$_POST['birth'];
$city=$_POST['city'];
$location=$_POST['location'];
$user_name=$_POST['user_name'];
$desc=$_POST['desc'];
$disab=$_POST['disab'];
$pass=$_POST['pass'];
$sql = "INSERT INTO exam1 (f_name, l_name, email, birth, city, location, user_name, desc, disab, pass)
VALUES ('$f_name', '$l_name', '$email', '$birth', '$city', '$location', '$user_name', '$desc', '$disab', '$pass')";
if ($conn->query($sql) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
}
?>
我收到的消息
已成功连接错误:插入INTO考试1(f_name,l_name,电子邮件, 出生,城市,位置,用户名,desc,disab,通过)VALUES(“约翰”, “ doe”,“ TT@GMAIL.COM”,“ 1993”,“ sabh”,“ almnshia”,“ ali”,“ ss”,“ yes”, '120130')您的SQL语法有误;检查手册 对应于您的MySQL服务器版本以使用正确的语法 'desc,disab,pass附近)VALUES('john','doe','TT@GMAIL.COM', 第1行的'1993','sabh','almn'
我使用navicat lite 我确定数据库名称和表名称以及表中的字段名称