我是SQL的新手。请帮我解决这个问题。我试图通过表单从用户那里获取输入并将其保存到MySql数据库,但在很多尝试修复它之后最终得到以下错误:
无法执行INSERT INTO客户端(full_name, 电子邮件,m_no,来源,目的地,年龄,性别,c_no,c_cvc, end_date_month,end_date_year,cost)VALUES(' manohar', ' mkpmaxx24@gmail.com',' 4455226644',' panvel',' kharghar',' 22', '男',' 4545454',' 454',' 01',' 2018',' 83& #39)。
Insert.php
$conn = mysqli_connect("localhost", "root", "", "bus");
if($conn === false){
die("ERROR: Could not connect. " . mysqli_connect_error());
}
$full_name = mysqli_real_escape_string($conn, $_REQUEST['full_name']);
$email = mysqli_real_escape_string($conn, $_REQUEST['email']);
$m_no = mysqli_real_escape_string($conn, $_REQUEST['m_no']);
$source = mysqli_real_escape_string($conn, $_REQUEST['source']);
$destination = mysqli_real_escape_string($conn, $_REQUEST['destination']);
$age = mysqli_real_escape_string($conn, $_REQUEST['age']);
$gender = mysqli_real_escape_string($conn, $_REQUEST['gender']);
$c_no = mysqli_real_escape_string($conn, $_REQUEST['c_no']);
$c_cvc = mysqli_real_escape_string($conn, $_REQUEST['c_cvc']);
$end_date_month = mysqli_real_escape_string($conn, $_REQUEST['end_date_month']);
$end_date_year = mysqli_real_escape_string($conn, $_REQUEST['end_date_year']);
$cost = mysqli_real_escape_string($conn, $_REQUEST['cost']);
$sql = ("INSERT INTO customer (full_name, email, m_no, source, destination, age, gender, c_no, c_cvc, end_date_month, end_date_year, cost) VALUES ('$full_name', '$email', '$m_no', '$source', '$destination', '$age', '$gender', '$c_no', '$c_cvc', '$end_date_month', '$end_date_year', '$cost')");
if(mysqli_query($conn,$sql)){
echo "Records added successfully.";
} else{
echo "ERROR: Could not able destination execute $sql. " . mysqli_error($conn);
}
mysqli_close($conn);
?>
conn.php
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
?>
bus.sql:
USE bus;
CREATE TABLE IF NOT EXISTS `customer` (
`full_name` varchar(50) NOT NULL,
`email` varchar(50) NOT NULL,
`m_no`int(11) NOT NULL AUTO_INCREMENT,
`source` varchar(50) NOT NULL,
`destination` varchar(50) NOT NULL,
`Age` int(5) NOT NULL,
`gender` varchar(50) NOT NULL,
`c_no`int(10) NOT NULL,
`c_cvc`int(10) NOT NULL,
`end_date_month` int(10) NOT NULL,
`end_date_year`int(10) NOT NULL,
`cost`int(10) NOT NULL,
PRIMARY KEY (`m_no`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 AUTO_INCREMENT=2 ;
INSERT INTO customer (`full_name`, `email`, `m_no`, `source`, `destination`, `age`, `gender`, `c_no`, `c_cvc`,`end_date_month`, `end_date_year`, `cost`) VALUES
(1, 'manohar patil', 4467895321, 'panvel', 'kharghar', 22,'male', 334422332233, 323, 12, 2022, 10);
谢谢。