error when connecting database to the form , and give me the below error

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



error when connecting database to the form , and give me the below error



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.


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





Your missing a opening quote in VALUES($pfn','$pe'
– Nigel Ren
Aug 12 at 7:03


VALUES($pfn','$pe'





well i edited and then i got this Error Number: 1136 Column count doesn't match value count at row 1 INSERT INTO add_clinic VALUES('Hassan ali ','hassanaliraafat@gmail.com','01000450292','20','30','20','30','120','15:52') Filename: C:/wamp/www/easyclinic/system/database/DB_driver.php Line Number: 691
– Hassan Ali
Aug 12 at 7:08





1 Answer
1



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...


VALUES($pfn'


$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.





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 (pfn, pe, pmn,pa,pw,ph,pgt,pbp,pec ) VALUES('$pfn','$pe','$pmn','$pa','$pw','$ph','$pgt','$pbp','$pec')"); what esle should i do thanks nigel ren
– Hassan Ali
Aug 12 at 7:24



pfn


pe


pmn


pa


pw


ph


pgt


pbp


pec





Are your database columns called pfn, your image of your table definition seems to have Patient Full Name.
– Nigel Ren
Aug 12 at 7:25



pfn


Patient Full Name





yeah now it's working right thanks
– Hassan Ali
Aug 12 at 7:33







By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

Creating a leaderboard in HTML/JS