メールフィールド以外のすべてのフィールドをデータベースに挿入できます。「Undefined index: em in C:\wamp\www\ins_db.php on line 11」というエラーが表示されます。メールのデータ型は次のとおりです。
email varchar(20) not null,
フォームコード:
<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>
以下は、フォーム データを受け取る完全な php コードです。
<?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);
?>