无法执行INSERT INTO <tablename>的目标

时间:2018-03-29 16:35:28

标签: php mysql database

我是SQL的新手。请帮我解决这个问题。我试图通过表单从用户那里获取输入并将其保存到MySql数据库,但在很多尝试修复它之后最终得到以下错误:

  

无法执行INSERT INTO客户端(full_name,   电子邮件,m_no,来源,目的地,年龄,性别,c_no,c_cvc,   end_date_month,end_date_year,cost)VALUES(&#39; manohar&#39;,   &#39; mkpmaxx24@gmail.com',&#39; 4455226644&#39;,&#39; panvel&#39;,&#39; kharghar&#39;,&#39; 22&#39;,   &#39;男&#39;,&#39; 4545454&#39;,&#39; 454&#39;,&#39; 01&#39;,&#39; 2018&#39;,&#39; 83& #39)。

  1. 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);
    
    ?>
    
  2. conn.php

    // Check connection
    if (mysqli_connect_errno()) {
      echo "Failed to connect to MySQL: " . mysqli_connect_error();
    }
    ?>
    
  3. 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);
    
  4. 谢谢。

0 个答案:

没有答案