Professional Documents
Culture Documents
Mainlab
Mainlab
:11
Creating database and inserting table data using my sql
Date:20.06.2022
AIM:
To create a database and to insert data using the my sql in the form of tables
SOURCE CODE:
To create the form using HTML
<!DOCTYPE>
<html>
<head>
<title>Giveaway challenge</title>
input[type=submit] {width: 8em; height: 1.5em; font-size:25px; color:Green;}
</style>
</head>
<body>
<center><h1><u>Netflix Giveaway Home week specially for INDIAN's</u></h1></center>
<marquee direction="left">
<h4 style="color:yellowgreen; font-size:49px"><strong>Win the world toppest brand goods for
free by lucky draw</strong></font>
</marquee>
<form style="font-size:25px; color:violet" action="sqlwork.php" method="post">
First name:<input type="text" id="fname" name="fname" placeholder="Sam"><br><br>
Last name:<input type="text" id="lname" name="lname" placeholder="Aakash"><br><br>
Date of birth:<input type="date" id="DOB" name="DOB" placeholder="01/01/1990"><br><br>
Contact number: <input type="number" id="contact" name="contact"
placeholder="0000000000"><br><br>
Email:<input type="email" id="email" name="email"
placeholder="abc@gmail.com"><br><br> Netflix Id:<input type="text" name="nid"
placeholder="NF00001"><br><br>
Gender:<br>
<input type="radio" id="male" name="Gender" value="male">
<label for="male">Male</label><br>
<input type="radio" id="female" name="Gender" value="female">
<label for="female">Female</label><br>
<input type="radio" id="Others" name="Gender" value="Others">
<label for="Others">Others</label></p1><br><br>
Nationality:<input type="checkbox" name="ind" value="Indian">Indian
<input type="checkbox" name="ind" value="Others">Others<br><br>
Home address:<br><textarea name="address" rows="7" cols="60"></textarea><br><br>
Pincode: <input type="number" name="pincode" placeholder="600000"><br><br>
Are your family member a Netflix employee?
<select name="test" id="test">
<option value="Yes">Yes</option>
<option value="No">No</option></select><br><br>
Rate Netflix out of 5:
<select name="rate" id="rate">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select><br><br>
<center><font style="font-size:40px; color:green;"><u>Answer the following 3 question to win the
lucky draw</u></font></center>
<p5 style="color:lightblue">1) When did netflix started?</p5><br>
<input type="checkbox" name="q1" value="a">1997<br>
<input type="checkbox" name="q1" value="b">1948<br>
<input type="checkbox" name="q1" value="c">2003<br>
<input type="checkbox" name="q1" value="d">1984<br><br>
<p6 style="color:lightblue">2) Founder of NETFLIX</p6><br>
<input type="checkbox" name="q2" value="a">Reed Hastings<br>
<input type="checkbox" name="q2" value="b">Marc Randolph<br>
<input type="checkbox" name="q2" value="c">Elon Musk<br>
<input type="checkbox" name="q2" value="d">Both a and b<br><br>
<p7 style="color:lightblue">3) Headquarters of NETFLIX:</p7><br>
<input type="checkbox" name="q3" value="a">Chinna<br>
<input type="checkbox" name="q3" value="b">India<br>
<input type="checkbox" name="q3" value="c">Russia<br>
<input type="checkbox" name="q3" value="d">Los Gatos<br><br>
<center><font style="font-size:40px; color:yellow;">I hereby declare that above all my personal
details are correct.</font></center><br><br>
<center><input type="submit" value="Submit"></center>
</form>
</body>
</html>
<?php
$link=mysqli_connect("localhost","root","","Netflixform");
if ($link===false){
die("ERROR: could not connect.".mysqli_connect_error($link));
}
$sql1="INSERT INTO
formdatawork(firstname,lastname,dateofbirth,netflixid,gender,email,nationality,address,pincode,rel
ativeworking,ratings) values
('$_POST[fname]','$_POST[lname]','$_POST[DOB]','$_POST[nid]','$_POST[Gender]','$_POST[e
mail]','$_POST[ind]','$_POST[addres],'$_POST[pin]','$_POST[test]','$_POST[rate]')";
$sql2=”INSERT INTO answer (name,q1,q2,q3)
values('$_POST[fname]','$_POST[q1]','$_POST[q2]','$_POST[q3]')";
if (mysqli_query($link,$sql1)&&(mysqli_query($link,$sql2)))
{
echo"Records added successfully.";
}
else
{echo"ERROR:could not able to execute $sql.".mysqli_error($link);
}
mysqli_close($link);?>
OUTPUT:
To create the table in command prompt and to display the data in table format:
RESULT:
The database was created and the data retrieved by HTML forms and the data collected from
the forms were inserted into table using mysql was executed successfully.