我在php中创建了一个html表单。我需要从表单中获取用户输入并需要在数据库中提交。对于邮件ID,它显示为邮件ID而不是我输入的邮件ID。需要显示我输入的邮件ID。
<html>
<head>
<title>child info</title>
</head>
<body>
<?php
if(isset($_POST['save']))
{
$dbhost = 'localhost';
$dbuser = 'admin';
$dbpass = 'admin@123';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn )
{
die('Could not connect: ' . mysql_error());
}
if(! get_magic_quotes_gpc() )
{
$ChildName = addslashes ($_POST['ChildName']);
$DOB = addslashes ($_POST['DOB']);
$Gender = addslashes ($_POST['Gender']);
$Grade = addslashes ($_POST['Grade']);
$BloodGroup = addslashes ($_POST['BloodGroup']);
$FatherName = addslashes ($_POST['FatherName']);
$MotherName = addslashes ($_POST['MotherName']);
$GuardianName = addslashes ($_POST['GuardianName']);
$LandlineNumber = addslashes ($_POST['LandlineNumber']);
$MobileNumber = addslashes ($_POST['MobileNumber']);
$Email_Id = addslashes ($_POST['Email_Id']);
$Child_Photo = addslashes ($_POST['Child_Photo']);
$Address = addslashes ($_POST['Address']);
}
else
{
$ChildName = $_POST['ChildName'];
$DOB = $_POST['DOB'];
$Gender =$_POST['Gender'];
$Grade = $_POST['Grade'];
$BloodGroup = $_POST['BloodGroup'];
$FatherName = $_POST['FatherName'];
$MotherName = $_POST['MotherName'];
$GuardianName = $_POST['GuardianName'];
$LandlineNumber =$_POST[' LandlineNumber'];
$MobileNumber = $_POST['MobileNumber'];
$Email_Id = $_POST['Email_Id'];
$Child_Photo = $_POST['Child_Photo'];
$Address = $_POST['Address'];
}
$sql = "INSERT INTO child_info(ChildName,DOB,Gender,Grade,BloodGroup,FatherName,MotherName,GuardianName,LandlineNumber,MobileNumber,Email_Id,Child_Photo,Address) VALUES ('$ChildName','$DOB','$Gender','$Grade','$BloodGroup','$FatherName','$MotherName','$GuardianName','$LandlineNumber','$MobileNumber','Email_Id','$Child_Photo','$Address')";
mysql_select_db('admin_data');
$retval = mysql_query( $sql, $conn );
if(! $retval )
{
die('Could not enter data: ' . mysql_error());
}
echo "Entered data successfully\n";
mysql_close($conn);
}
else
{
?>
<!DOCTYPE HTML>
<head>
<title>child_info</title>
<link rel="stylesheet" type="text/css" href="css/child_info.css">
<script src="js/notification.js"> </script>
</head>
<body>
<div>
<div class="layout">
<div class="img1"></div>
<div class="menu">
<form method="post" action="<?php $_PHP_SELF ?>" >
<label class="ChildName">CHILD NAME</label><input type="text" placeholder="ChildName" id="ChildName" name="ChildName">
<label class="DOB">DATE OF BIRTH</label><input type="date" placeholder="D.O.B" id="DOB" name="DOB">
<label class="Gender">GENDER</label>
<label class="Male">Male</label><input type="radio" name="Gender" value="male" id="Gender" >
<label class="Female">Female</label><input type="radio" name="Gender" value="female" id="Gender">
<label class="Grade1">GRADE</label>
<select class=" Grade" id="Grade" name="Grade">
<option>KG1</option><option>KG2</option><option>A</option><option>B</option>
<option>C</option><option>D</option><option>E</option>
<option>F</option><option>G</option><option>H</option><option>I</option><option>J</option><option>K</option>
</select>
<label class="BloodGroup">BLOOD GROUP</label><input type="text" placeholder="BLOOD GROUP" id="BloodGroup" name="BloodGroup">
<label class="FatherName">FATHER NAME</label><input type="text" placeholder="FATHER NAME" id="FatherName" name="FatherName">
<label class="MotherName">MOTHER NAME</label><input type="text" placeholder="MOTHER NAME" id="MotherName" name="MotherName">
<label class="GuardianName">GUARDIAN NAME</label><input type="text" placeholder="GUARDIAN NAME" id="GuardianName" name="GuardianName">
<label class="LandlineNumber">LANDLINE</label><input type="tel" placeholder="LANDLINE" id="LandlineNumber" name="LandlineNumber">
<label class="MobileNumber">MOBILE NUMBER</label><input type="tel" placeholder="MOBILE NUMBER" id="MobileNumber" name="MobileNumber">
<label class="Email_Id">MAIL ID</label><input type="email" placeholder="MAIL ID" id="Email_Id" name="Email_Id">
<label class="child_image">CHILD PHOTO</label><input type="file" id="Child_Photo" name="Child_Photo">
<label class="Address">Address</label><textarea id="Address" name="Address" rows="8" cols="40"></textarea>
<input type="submit" value="save" id="save" name="save">
<!--<input type="reset" button onclick='window.location="menu.php"' name="Send Notification" id="save" value="Save">
<input type="reset" button onclick="javascript:eraseText() name="reset" id="reset" value="Reset">-->
</form>
</div>
</div>
</div>
<?php
}
?>
</body>
</html>
答案 0 :(得分:0)
您的问题出在您的查询中,您在此行中$
前面缺少Email_Id
:
$sql = "INSERT INTO child_info(ChildName,DOB,Gender,Grade,BloodGroup,FatherName,MotherName,GuardianName,LandlineNumber,MobileNumber,Email_Id,Child_Photo,Address) VALUES ('$ChildName','$DOB','$Gender','$Grade','$BloodGroup','$FatherName','$MotherName','$GuardianName','$LandlineNumber','$MobileNumber','Email_Id','$Child_Photo','$Address')";
如果将行更改为
,它应该有效$sql = "INSERT INTO child_info(ChildName,DOB,Gender,Grade,BloodGroup,FatherName,MotherName,GuardianName,LandlineNumber,MobileNumber,Email_Id,Child_Photo,Address) VALUES ('$ChildName','$DOB','$Gender','$Grade','$BloodGroup','$FatherName','$MotherName','$GuardianName','$LandlineNumber','$MobileNumber','$Email_Id','$Child_Photo','$Address')";
但是,正如马里奥所说,你应该真正研究适当的数据库转义,例如PDO。
答案 1 :(得分:0)
问题出在INSERT查询中,你错过了&#34; $&#34;签署电子邮件ID。