You are on page 1of 8

WEB PROGRAMMING ASSIGNMENT

PHP and MYSQL DATABASE CONNECTION

BALAJI_insert.php:

Source Code:

<html>

<head>

<title>STUDENTS DETAILS</title>

</head>

<body>

<font face="Verdana, Arial">

<table cellpadding="10" cellspacing="10" align="center">

<tbody>

<tr><td colspan="3" align="center">

<strong>Enter Student Detail</strong>

<br>

</td></tr>

<form name="form1" method="post" action="st_ins_data.php">

<tr>

<td>

<br>

<tr><td> Regn. No. </td><td> ::</td><td> <input name="balregno" maxlength="5"


type="text"></td></tr>

<tr><td> First Name. </td><td> ::</td><td> <input name="balfname" maxlength="30"


type="text"></td></tr>

<tr><td> Last Name. </td><td> ::</td><td> <input name="ballname" maxlength="30"


type="text"></td></tr>

<tr><td> Date of Birth. </td><td> ::</td><td> <input name="baldob" type="date"></td></tr>


<tr><td> Mobile No. </td><td> ::</td><td> <input name="balmobile" maxlength="10"
type="text"></td></tr>

<tr><td> Department </td><td> ::</td><td> <input name="baldept" maxlength="10"


type="text"></td></tr>

<tr><td> Email. </td><td> ::</td><td> <input name="balmail" maxlength="50"


type="text"></td></tr>

<tr><td> CGPA. </td><td> :: </td><td> <input name="balcgpa" maxlength="10"


type="text"></td></tr>

<tr><td> Gender. </td><td> ::</td><td> <input name="balgender" id="balgender"


type="radio">Male

<input name="balgender" id="balgender" type="radio">FeMale</td></tr>

<tr><td> Blood Group. </td><td> ::</td><td>

<select name="balbgrp" id="balbgrp" maxlength="10" type="selectbox" >

<option value="a+">A Positive</option>

<option value="b+">B Positive</option>

<option value="ab+">AB Positive</option>

<option value="ab-">AB Negative</option>

<option value="a-">A Negative</option>

<option value="b-">B Negative</option>

<option value="un">Unknown</option>

</select></td></tr>

<tr><td> Home Address </td><td> ::</td><td> <input name="baladd" maxlength="50"


type="text"></td></tr>

<tr><td> City</td><td> ::</td><td> <input name="balcity" maxlength="20" type="text"></td></tr>


<tr><td>State </td><td> ::</td><td> <input name="balstate" maxlength="10"
type="text"></td></tr>

<tr><td>Zip Code </td><td> ::</td><td> <input name="balcode" maxlength="10"


type="text"></td></tr>

</div>

</td></tr>

<tr>

<td colspan="3" height="52" align="center">

<input name="Submit1" value="Insert" type="submit"> &nbsp; &nbsp; &nbsp

<input name="Submit2" value="Reset" type="reset">

</td>

</tr>

</form>

</font>

</tbody>

</table>

</body>

</html>

2.Balaji_ins_data.php:

Source Code:

<html>

<head>

<title>Inserting new data</title>

</head>
<body>

<table border='1'>

<?php

$bregno = $_POST["balregno"];

$bfname = $_POST["balfname"];

$blname = $_POST["ballname"];

$bdob = $_POST["baldob"];

$bmobile = $_POST["balmobile"];

$bdept = $_POST["baldept"];

$bmail = $_POST["balmail"];

$bcgpa = $_POST["balcgpa"];

$bgender = $_POST["balgender"];

$bbgrp = $_POST["balbgrp"];

$badd = $_POST["baladd"];

$bcity = $_POST["balcity"];

$bstate = $_POST["balstate"];

$bcode = $_POST["balcode"];

$dsn = "mysql:dbname=mca";

$username = "root";

$password = "";

$conn = new PDO( $dsn, $username, $password );

$strquery = "insert into mca2 values


(:bregno, :bfname, :blname,:bdob,:bmobile,:bdept,:bmail,:bcgpa,:bgender,:bbgrp,:badd,:bcity,:bstat
e,:bcode)";

try {

$st = $conn->prepare($strquery);
$st->bindValue( ":bregno", $bregno, PDO::PARAM_INT );

$st->bindValue( ":bfname", $bfname, PDO::PARAM_INT );

$st->bindValue( ":blname", $blname, PDO::PARAM_INT );

$st->bindValue( ":bdob", $bdob, PDO::PARAM_INT );

$st->bindValue( ":bmobile", $bmobile, PDO::PARAM_INT );

$st->bindValue( ":bdept", $bdept, PDO::PARAM_INT );

$st->bindValue( ":bmail", $bmail, PDO::PARAM_INT );

$st->bindValue( ":bcgpa", $bcgpa, PDO::PARAM_INT );

$st->bindValue( ":bgender", $bgender, PDO::PARAM_INT );

$st->bindValue( ":bbgrp", $bbgrp, PDO::PARAM_INT );

$st->bindValue( ":badd", $badd, PDO::PARAM_INT );

$st->bindValue( ":bcity", $bcity, PDO::PARAM_INT );

$st->bindValue( ":bstate", $bstate, PDO::PARAM_INT );

$st->bindValue( ":bcode", $bcode, PDO::PARAM_INT );

$st->execute();

} catch (PDOException $e) {

echo "Query failed : ", $e->getMessage();

echo " Row inserted Successfully";

echo "<br>";

echo "<br>";

?>

</body>

</table>

</html>
OUTPUT:
FROM MYADMIN DASHBOARD:

Table and FieldNames:

You might also like