I've this form data to be sent to insert into database

Sam

I can insert all fields in database except email field. I get the following error "Undefined index: em in C:\wamp\www\ins_db.php on line 11" data type of email is below:

email varchar(20)  not null,

Form code:

<form action = "ins_db.php" method = "post">
<div class="reg"><br>
<br>All fields (*) are mandatory
<br>
User Id *<input type = "text" name = "id"><br><br>
Password *<input type = "password" name = "pwd"><br><br>
Confirm Password *<input type = "password" name = "cpwd"><br><br>
First Name *<input type = "text" name = "fname"><br><br>
Last Name *<input type = "text" name = "lname"><br><br>
Contact *<input type = "number" name = "contact"><br><br>
E-mail *<input type = "text" name ="em"><br><br>
Date of Birth *<input type = "date" name = "dob"><br><br>
<span>Qualification *
<select name = "qualification">
  <option value="B.Sc">B.Sc</option>
  <option value="M.Sc">M.Sc</option>
  <option value="Ph.d">Ph.d</option>
  <option value="B.Tech">B.Tech</option>
  <option value="B.Tech">B.Tech</option>
</select></span><br><br>
Experience *<input type = "number" name = "exp"><br><br>
Gender *<input type = "text" name = "gender"><br><br>
Address *<textarea cols="40" rows="5" name = "address">
Enter your address
</textarea><br><br>
Country *<input type = "text" name = "country"><br><br>
Religion *<input type = "text" name = "religion"><br><br>
Hint question *<input type = "text" name = "qhint"><br><br>
Hint answer *<input type = "text" name = "ahint"><br><br>
<?php
  $timezone = "Asia/Kolkata";
  date_default_timezone_set($timezone);
  $today = date("Y-m-d");
?>
ID created On *<input type = "date" name = "createon" value="<?php echo $today; ?>"><br><br>
<input type = "submit" value = "Submit">
</div>
</form>

Following is the full php code which receives form data

<?php
$con = mysqli_connect('localhost','root','','jobhunt');
if(!$con)
{
echo "Can not connect to DB";
}
if(isset($_POST['id']))
echo "suceecess";
if(isset($_POST['em'])){
$em = $_POST['em'];
}
else 
echo "empty";
if(isset($_POST))
{
$query = "INSERT INTO seeker(sid,fname,lname,contact,email,dob,gender,address,religion,experience,qualification,created)
VALUES
('$_POST[id]','$_POST[fname]','$_POST[lname]','$_POST[contact]','$_POST[em]','$_POST[dob]','$_POST[gender]','$_POST[address]','$_POST[religion]','$_POST[exp]','$_POST[qualification]','$_POST[createon]')";
}
if (!mysqli_query($con,$query))
  {
  die('Error: ' . mysqli_error($con));
  }
echo "1 record added";

mysqli_close($con);
?>
shennan

Test for a value in each individual POST variable. Replace your PHP code with this:

<?php

    $con = mysqli_connect('localhost','root','','jobhunt');

    if(!$con){
        echo "Can not connect to DB";
        exit;
    }

  $keys = array('id', 'fname', 'lname', 'contact', 'em', 'dob', 'gender', 'address', 'religion', 'exp', 'qualification', 'createon');
  $query = "INSERT INTO seeker(sid,fname,lname,contact,email,dob,gender,address,religion,experience,qualification,created) VALUES (";

  foreach($keys as $key){

    if(isset($_POST[$key])){

      $query .= "'" . $_POST[$key] . "'";

    }else{

      $query .= "''";

    }

    if($key === end($keys)){

      $query = ");";

    }else{

      $query .= ",";

    }
  }

  if (!mysqli_query($con,$query)){
    die('Error: ' . mysqli_error($con));
  }else{
    echo "success";
  }

  mysqli_close($con);

?>

As a side note, inserting straight from POST variables into a database is a serious security risk.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

I've this form data to be sent to insert into database

From Dev

Data entered in the form is not being sent to the Oracle Database

From Dev

Data entered in the form is not being sent to the Oracle Database

From Dev

Flowgear Insert form post data into database

From Dev

PHP Creating Form to insert data into Database

From Dev

how do i insert data into my H2 database using a form

From Dev

how can i insert data from a html form into mysql database 2

From Dev

how do i insert data into my H2 database using a form

From Dev

Data not being sent to database

From Dev

No data sent to MySQL database

From Dev

How can I insert data into Database Laravel?

From Dev

how i insert 1 data with 2 string? and insert into database?

From Dev

Dynamic form insert database

From Dev

SQL - Insert form into a database

From Dev

My mongoose test fails unless I repeatedly check the data I've saved in the database

From Dev

insert data to mysql database from multiple select list (html form)

From Dev

Insert data into Wordpress database table from a custom form

From Dev

How to Insert multiple Form Data in CakePHP as new row in database

From Dev

Data from form being shown as gibberish in database after insert query

From Dev

INSERT IMAGE INTO DATABASE and enctype="multipart/form-data"

From Dev

HTML/PHP form doesn't insert data to MySQL Database

From Dev

Data from form being shown as gibberish in database after insert query

From Dev

how to insert a form post data into database in yii 1 framework

From Dev

I got an SQL error, trying to insert a form to the database

From Dev

I cannot insert records into Database using HTML Form and PHP

From Dev

Wrong Data being sent to Mysql database from VB.net through paramatized insert statement

From Dev

Form Data Not Being Sent In ColdFusion

From Dev

Which data is sent via form?

From Dev

why is the file not being sent in POST variable even though I have enctype="multipart/form-data" in the form

Related Related

  1. 1

    I've this form data to be sent to insert into database

  2. 2

    Data entered in the form is not being sent to the Oracle Database

  3. 3

    Data entered in the form is not being sent to the Oracle Database

  4. 4

    Flowgear Insert form post data into database

  5. 5

    PHP Creating Form to insert data into Database

  6. 6

    how do i insert data into my H2 database using a form

  7. 7

    how can i insert data from a html form into mysql database 2

  8. 8

    how do i insert data into my H2 database using a form

  9. 9

    Data not being sent to database

  10. 10

    No data sent to MySQL database

  11. 11

    How can I insert data into Database Laravel?

  12. 12

    how i insert 1 data with 2 string? and insert into database?

  13. 13

    Dynamic form insert database

  14. 14

    SQL - Insert form into a database

  15. 15

    My mongoose test fails unless I repeatedly check the data I've saved in the database

  16. 16

    insert data to mysql database from multiple select list (html form)

  17. 17

    Insert data into Wordpress database table from a custom form

  18. 18

    How to Insert multiple Form Data in CakePHP as new row in database

  19. 19

    Data from form being shown as gibberish in database after insert query

  20. 20

    INSERT IMAGE INTO DATABASE and enctype="multipart/form-data"

  21. 21

    HTML/PHP form doesn't insert data to MySQL Database

  22. 22

    Data from form being shown as gibberish in database after insert query

  23. 23

    how to insert a form post data into database in yii 1 framework

  24. 24

    I got an SQL error, trying to insert a form to the database

  25. 25

    I cannot insert records into Database using HTML Form and PHP

  26. 26

    Wrong Data being sent to Mysql database from VB.net through paramatized insert statement

  27. 27

    Form Data Not Being Sent In ColdFusion

  28. 28

    Which data is sent via form?

  29. 29

    why is the file not being sent in POST variable even though I have enctype="multipart/form-data" in the form

HotTag

Archive