duanqu9279 2018-08-12 06:59
浏览 43
已采纳

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

I am try to fill the form and I got this error. Please someone tell me why?
I have attached all the code and the images: what I want is when I fill this form, it gets automatically saved in database. And please, if you can provide me how to upload images from the same form to the same database at phpmyadmin.

Error Message:

enter image description here

This is the model :

 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');

This is the controller

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
   }



     }

this is the 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>

and this is the image of phpmyadmion: see phpmyadmin iamge

  • 写回答

1条回答 默认 最新

  • dongxian1921 2018-08-12 07:15
    关注

    There is a minor error of a missing ' in your columns of the INSERT statement (VALUES($pfn'), but also there is also a problem of matching the columns up. I would normally list the columns that I am inserting into as well, something like...

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

    (Where *** is just a list of the columns to be inserted into).

    There are two recommendations I would like to make - firstly is to change the names of your columns. Having spaces in column names can cause all sorts of problems and is not normally recommended.

    Secondly is to look into using prepared statements and bind variables, this will provide all sorts of benefits later, including security and not having problems with certain characters in the text.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 delta降尺度方法,未来数据怎么降尺度
  • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
  • ¥15 再不同版本的系统上,TCP传输速度不一致
  • ¥15 高德地图点聚合中Marker的位置无法实时更新
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程