PHP-Mysql -data插入问题 [英] PHP-Mysql -data insert problem
本文介绍了PHP-Mysql -data插入问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的问题是如何插入mysql数据库男性/女性和标记(%)?
my html代码
使用mysqli-student数据插入数据
my question is how insert mysql database male/female and marks(%)?
my html code
insert data using mysqli-student data
<div id="submit"><h3>Student Data</h3>
<form method="post" action="input.php">
<label>student name:
<input type="text" name="name" id ="name" required="required" placeholder="Please Enter Name"/>
<p><br />
<label>student Last name:
<input type="text" name="Lname" id ="Lname" required="required" placeholder="Please Last Name"/><p><br />
<label>student Age:
<input type="text" name="age" id ="age" required="required" placeholder="Enter student Age"/>
<p><br />
<label>student DOB:
<input type="date" name="date" id ="date" required="required" placeholder="Enter student DOB"/>
<p><br />
<label>student sex:
<select id="sex" name="sex">
<option value="1">male</option>
<option value="2">female</option>
</select>
<p><br />
<label>student mark(out of 500):
<input type="text" name="mark" id ="mark" required="required" placeholder="Please Enter Mark"/><p><br />
<label>student mark(% of mark):
<input type="text" name="pmark" id ="pmark" required="required" placeholder="percentage"/><p><br />
<label>student place:
<input type="text" name="place" id ="place" required="required" placeholder="Enter student place"/>
<p><br />
<input type="submit" name="submit" value="sent"
<br />
</form></p></p></p></p></p></p></p></p></div>
和我的PHP代码
And my PHP Code
// create connection
$conn= mysqli_connect ('localhost','root','','mydb');
if(mysqli_connect_errno())
{
echo" failed to conncet:" .mysqli_connect_errno();
}
$sql= "INSERT INTO mydb(name, Lname,age,date,sex,mark,pmark,place)
VALUES ('$_POST[name]','$_POST[Lname]','$_POST[age]','$_POST[date]','$_POST[sex]','$_POST[mark]','$_POST[pmark]','$_POST[place]')";
if(!mysqli_query($conn,$sql))
{
die('Error:'.mysqli_error($conn));
}
echo "1 record added"
?>
推荐答案
conn = mysqli_connect(' localhost', ' root',' ',' mydb');
if(mysqli_connect_errno())
{
echo 无法执行: .mysqli_connect_errno();
}
conn= mysqli_connect ('localhost','root','','mydb'); if(mysqli_connect_errno()) { echo" failed to conncet:" .mysqli_connect_errno(); }
sql = INSERT INTO mydb(name,Lname ,年龄,日期,性别,标记,pmark,地方)
VALUES('
sql= "INSERT INTO mydb(name, Lname,age,date,sex,mark,pmark,place) VALUES ('
_POST [name]','
_POST[name]','
这篇关于PHP-Mysql -data插入问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文