将数据库连接到表单时出错,并给我以下错误

时间:2018-08-12 06:59:36

标签: php

我尝试填写表格,但出现此错误。请有人告诉我为什么?
我已经附上了所有代码和图像:我想要的是当我填写此表单时,它将自动保存在数据库中。而且,如果您能为我提供在phpmyadmin上如何将图像从相同的表单上传到相同的数据库。

错误消息:

enter image description here

这是模型:

 class Clinic_Model extends CI_Model 
 {
  function insert_into_db()
    {
    $pfn = $_POST['pfn'];
    $pe = $_POST['pe'];
    $pmn = $_POST['pmn'];
    $pa = $_POST['pa'];
    $pw = $_POST['pw'];
    $ph = $_POST['ph'];
    $pgt = $_POST['pgt'];
    $pbp = $_POST['pbp'];
    $pec = $_POST['pec'];

    $this->db->query("INSERT INTO add_clinic 
    VALUES($pfn','$pe','$pmn','$pa','$pw','$ph','$pgt','$pbp','$pec')");

}
}

  <?php
  defined('BASEPATH') OR exit('No direct script access allowed');

这是控制器

class Easyclinic extends CI_Controller {

   //----------Constructor----------
  public function __construct()
    {
    parent::__construct();
    $this->load->helper('url');
    //load Model
    $this->load->model('clinic_model');

   }
  //----------BaseFunctions----------
   public function index()
    {    
    $this->load->view('add_patient');
    }
    public function mydata()
    {
    $this->load->view('mydata');
   }
   public function addpatient()
   {
    $this->load->view('add_patient');
   }    

     //---------Advinced Functions---------

    public function insert_into_db()
    {
    $this->load->model('clinic_model');
    $this->clinic_model->insert_into_db();
    $this->load->view('success');//loading success view
   }



     }

这是视图

  <!DOCTYPE html>
     <html lang="en">
  <head>
  <title>Add Patient</title>
  <!-- for-mobile-apps -->
     <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
     <meta name="keywords" content="easyclinic" />
    <script type="application/x-javascript"> addEventListener("load", 
    function() { setTimeout(hideURLbar, 0); }, false);
    function hideURLbar(){ window.scrollTo(0,1); } </script>
   <!-- //for-mobile-apps -->
   <!-- //custom-theme -->
      <link href="assests/css/style.css" rel="stylesheet" type="text/css" 
media="all" />
 <!-- js -->
  <script type="text/javascript" src="assests/js/jquery-2.1.4.min.js"> 
 </script>
  <!-- //js -->

   <link href='//fonts.googleapis.com/css? 
   family=Roboto:400,100,300,500,700,900' rel='stylesheet' type='text/css'>
   </head>
  <body>
  <!-- banner -->
 <div class="center-container">
    <div class="main">
        <h1 class="w3layouts_head">Add Patient Info</h1>
        <h1 class="w3layouts_head">Welcome Dr.Atef</h1>
            <div class="w3layouts_main_grid">


                <form action="<?php echo base_url();? 
         >easyclinic/insert_into_db" method="post" class="w3_form_post">


     <!-- day/time -->
        <div class="agileits_w3layouts_main_grid w3ls_main_grid">
          <span class="agileinfo_grid">
            <label>Examination Date</label>
            <div class="agileits_w3layouts_main_gridl">
              <input class="date hasDatepicker" id="datepicker" name="Text" 
        type="text" value="dd/mm/yyyy" onfocus="this.value = '';" onblur="if 
       (this.value == '') {this.value = '';}" required="">
            </div>
            <div class="agileits_w3layouts_main_gridr">
              <input type="time" name="Time" placeholder=" " required="">
            </div>
              <div class="clear"> </div>
          </span>
        </div>

       <!--  name -->


        <div class="w3_agileits_main_grid w3l_main_grid">
          <span class="agileits_grid">
            <label>Patient Full Name </label>
            <input type="text" name="pfn" placeholder=" 4 part name" 
        required="">
          </span>
        </div>
     <!-- email  -->
        <div class="w3_agileits_main_grid w3l_main_grid">
          <span class="agileits_grid">
            <label>Patient Email </label>
            <input type="text" name="pe" placeholder=" Email" required="">
          </span>
        </div>
    <!-- Phone number -->
        <div class="w3_agileits_main_grid w3l_main_grid">
          <span class="agileits_grid">
            <label>Patient Number </label>
            <input type="text" name="pmn" placeholder="Phone Number" 
      required="">
            </span>
        </div>
       <!-- choose your Gender-->
      <div class="content-w3ls">
        <div class="form-w3ls">
          <div class="content-wthree2">
            <div class="grid-w3layouts1">
              <div class="w3-agile1">
                <label>Gender</label>
                <ul>
                  <li>
                    <input type="radio" id="a-option" name="pg">
                    <label for="a-option">Male </label>
                    <div class="check"></div>
                  </li>
                  <li>
                    <input type="radio" id="b-option" name="pg2">
                    <label for="b-option">female</label>
                    <div class="check"><div class="inside"></div></div>
                  </li>
                </ul>
              </div>  
            </div>
        <!--  age -->
            <div class="w3_agileits_main_grid w3l_main_grid">
              <span class="agileits_grid">
                <label>Patient Age </label>
                <input type="text" name="pa" placeholder="Patient Age" 
       required="">
              </span>
            </div>

            <div class="clear"></div>
          </div>
        </div>
      <!--  weight -->

            <div class="w3_agileits_main_grid w3l_main_grid">
              <span class="agileits_grid">
                <label>Weight</label>
                <input type="text" name="pw" placeholder="Weight in 
       KiloGrams" required="">
              </span>
            </div>
       <!--  Height -->

            <div class="w3_agileits_main_grid w3l_main_grid">
              <span class="agileits_grid">
                <label>Height</label>
                <input type="text" name="ph" placeholder="Height in 
       CentiMeters" required="">
              </span>
            </div>
    <!--  Glucose -->

            <div class="w3_agileits_main_grid w3l_main_grid">
             <span class="agileits_grid">
               <label>Glucose Test</label>
               <input type="text" name="pgt" placeholder="~100~140" 
         required="">
             </span>
            </div>

        <!--  Heart pressure -->
            <div class="w3_agileits_main_grid w3l_main_grid">
              <span class="agileits_grid">
                <label>Blood Pressure</label>
                <input type="text" name="pbp" placeholder="~120~180" 
           required="">
              </span>
            </div>
           <!-- Uoload File -->
        <div>
        <span class="agileits_grid">  
        <label>Upload sonar image</label>
        <form method="post" enctype="multipart/form-data" action="upload"> 
        </br>
              Choose a file: 
        <input type="image" name="usi" /> 
        <input type="submit" />
        </form>
        </div>
           <!-- Uoload File -->
        <div>
        <span class="agileits_grid">  
        <label>Upload cbc image</label>
        <form method="post" enctype="multipart/form-data" action="upload">
              Choose a file: 
        <input type="image" name="uci" /> 
        <input type="submit" />
        </form>
        </div>

         <!-- day/time -->

        <div class="agileits_w3layouts_main_grid w3ls_main_grid">
          <span class="agileinfo_grid">
            <label>Expectation of Childbirth</label>
            <div class="agileits_w3layouts_main_gridl">
              <input class="date hasDatepicker" id="datepicker" name="Text" 
             type="text" value="mm/dd/yyyy" onfocus="this.value = '';" 
        onblur="if (this.value == '') {this.value = '';}" required="">
            </div>
            <div class="agileits_w3layouts_main_gridr">
              <input type="time" name="pec" placeholder=" " required="">
            </div>
              <div class="clear"> </div>
          </span>
        </div>  


             <!-- submit button -->

                <div class="w3_main_grid">
                    <div class="w3_main_grid_right">
                        <input type="submit" name="save" value="Submit">
                    </div>
                </div>
            </form>
        </div>




          <!-- Calendar -->
        <link rel="stylesheet" href="assests/css/jquery-ui.css" />
            <script src="js/jquery-ui.js"></script>
                <script>
                    $(function() {
                        $( "#datepicker" ).datepicker();
                    });
                </script>
        <!-- //Calendar -->



        <div class="w3layouts_copy_right">
            <div class="container">
                <p>© 2018 Patient Registration Form. All rights reserved |  
        <a href="http://w3layouts.com">HassanAli</a></p>
            </div>
        </div>
        </div>
        </div>
             <!-- //footer -->
                </body>
                    </html>

这是phpmyadmion的图像: see phpmyadmin iamge

1 个答案:

答案 0 :(得分:0)

在INSERT语句(VALUES($pfn')的列中缺少'的小错误,但同时也存在将列匹配的问题。通常,我也会列出我要插入的列,例如...

$this->db->query("INSERT INTO add_clinic (`Patient Full Name`, *** )
    VALUES('$pfn','$pe','$pmn','$pa','$pw','$ph','$pgt','$pbp','$pec')");

(其中***只是要插入的列的列表)。

我要提出两个建议-首先是更改列的名称。列名中包含空格会导致各种问题,通常不建议这样做。

第二,要研究使用准备好的语句和绑定变量,这将在以后提供各种好处,包括安全性以及文本中某些字符没有问题。