Click here to Skip to main content
15,893,790 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
my question is how insert mysql database male/female and marks(%)?

my html code

insert data using mysqli-student data


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

And my PHP Code

PHP
// 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"


?>
Posted
Updated 26-Jul-15 22:28pm
v2
Comments
Mohibur Rashid 27-Jul-15 1:29am    
Past few days, I have been answering the same. Take a took at mysqli_real_escape_string
[no name] 27-Jul-15 4:45am    
What is the issues your getting?
Member 10011989 19-Sep-15 4:11am    
is there any error you are face or what else?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900