0% found this document useful (0 votes)
18 views9 pages

PHP Database Practical Part

1. The document contains PHP code for user registration and storing registration data into a MySQL database. 2. It includes PHP pages for creating a database and table, a registration form, storing form data into the database, and displaying all registration data from the database in a table. 3. Functions like connecting to the database, inserting, selecting and displaying records are demonstrated.

Uploaded by

Hirpara Krush
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views9 pages

PHP Database Practical Part

1. The document contains PHP code for user registration and storing registration data into a MySQL database. 2. It includes PHP pages for creating a database and table, a registration form, storing form data into the database, and displaying all registration data from the database in a table. 3. Functions like connecting to the database, inserting, selecting and displaying records are demonstrated.

Uploaded by

Hirpara Krush
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Asst. Prof.

Viral Patel PHP Database Program Subject: 504 Web Framework and Services

registration.php localhost/ty1/registration.php

<html>
<header>
</header>
<body>
<form action="regdatastore.php">
<table border="5px" style="margin:auto;border-collapse:collapse;">
<tr>
<td> </td>
<td> <b>Registration Page</b></td>
</tr>
<tr>
<td> Name:</td>
<td> <input type="text" name="nam"></td>
</tr>
<tr>
<td> Password:</td>
<td> <input type="password" name="pass1"></td>
</tr>
<tr>
<td> Retype Password:</td>
<td> <input type="password" name="pass2"></td>
</tr>
<tr>
<td> Enter Mobile:</td>
<td> <input type="text" name="mob"></td>
</tr>
<tr>
<td> Select Course:</td>
<td>
<input type="radio" name="sub" value="BCA">BCA
<input type="radio" name="sub" value="BBA">BBA
<input type="radio" name="sub" value="BCOM">BCOM
</td>
</tr>

Shri. Shambhubhai V. Patel College of CS and BM, Surat


Asst. Prof. Viral Patel PHP Database Program Subject: 504 Web Framework and Services

<tr>
<td> Select Hobbies:</td>
<td>
<input type="checkbox" name="hb1" value="1">Travelling
<input type="checkbox" name="hb2" value="1">Sports
<input type="checkbox" name="hb3" value="1">Music
</td>
</tr>
<tr>
<td> City:</td>
<td>
<select name="city" id="city">
<option value="select" selected>---select---</option>

<option value="surat" >surat</option>


<option value="ahmedabad">ahmedabad</option>
<option value="bharuch">bharuch</option>
<option value="baroda">baroda</option>
<option value="valsad">valsad</option>
</select>
</td>
</tr>
<tr>
<td>Address:</td>
<td><textarea name="addr"></textarea></td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="btnsub"> </td>
</tr>
</table>
</form>
</body>
</html>

Shri. Shambhubhai V. Patel College of CS and BM, Surat


Asst. Prof. Viral Patel PHP Database Program Subject: 504 Web Framework and Services

createDatabase.php createTable.php
<?php <?php

$conn = mysqli_connect("localhost","root",""); $conn = mysqli_connect("localhost","root","","mydb");

$sql = "create database mydb"; $sql = "create table REGISTRATION


(
mysqli_query($conn,$sql); id int primary key AUTO_INCREMENT,
name varchar(20),
echo "<br>database created successfully"; pass varchar(10),
mobile varchar(10),
mysqli_close($conn); subject varchar(5),
travelling bit(1),
?> sports bit(1),
music bit(1),
city varchar(15),
address varchar(50)
)";

mysqli_query($conn,$sql);

echo "<br>table created successfully";

mysqli_close($conn);

?>

Shri. Shambhubhai V. Patel College of CS and BM, Surat


Asst. Prof. Viral Patel PHP Database Program Subject: 504 Web Framework and Services

regdatastore.php
<?php $conn = mysqli_connect("localhost","root","","mydb");
$nm=$p1=$p2=$mb=$sb=$h1=$h2=$h3=$ct=$ad=""; $sql = "insert into REGISTRATION
(name,pass,mobile,subject,travelling,sports,music,city,address)
if(isset($_GET['btnsub'])) values('$nm','$p1','$mb','$sb',B'$h1',B'$h2',B'$h3','$ct','$ad')";
{ //print_r($sql);
$nm = $_GET['nam'];
$p1 = $_GET['pass1']; mysqli_query($conn,$sql);
$p2 = $_GET['pass2']; echo "data inserted successfully";
$mb = $_GET['mob']; }
$sb = $_GET['sub']; ?>
if(isset($_GET['hb1']))
$h1 = 1;
else
$h1 = 0;
if(isset($_GET['hb2']))
$h2 = 1;
else
$h2 = 0;
if(isset($_GET['hb3']))
$h3 = 1;
else
$h3 = 0;
$ct = $_GET['city'];
$ad = $_GET['addr'];
localhost/ty1/regdatastore.php?nam=Jay&pass1=Jay123&pass2=Jay123&mob=9999999999&sub=BBA&hb1=1&hb3=1&city=surat&addr=A-
202%2C+Shivalay%2C+Adajan&btnsub=Submit

Shri. Shambhubhai V. Patel College of CS and BM, Surat


Asst. Prof. Viral Patel PHP Database Program Subject: 504 Web Framework and Services

allRegDataDispInTable.php regEditDelete.php
<html> <html>
<body> <body>
<?php <?php
$conn = mysqli_connect("localhost","root","","mydb"); $conn = mysqli_connect("localhost","root","","mydb");

$sql = "select * from REGISTRATION"; $sql = "select * from REGISTRATION";


$res = mysqli_query($conn,$sql);
$res = mysqli_query($conn,$sql);
echo "<table border=1>";
echo "<table border=1>";
while($row=mysqli_fetch_array($res))
while($row=mysqli_fetch_array($res)) {
{ echo "<tr>";
echo "<tr>"; for($i=0;$i<10;$i++)
for($i=0;$i<10;$i++) {
{ echo "<td>$row[$i]</td>";
echo "<td>$row[$i]</td>"; }
} echo "<td><a href='regEditData.php?id=$row[0]'>edit</a></td>";
echo "</tr>"; echo "<td><a href='regDeleteData.php?id=$row[0]'>delete</a></td>";
} echo "</tr>";
}
echo "</table>";
?> echo "</table>";
</body> ?>
</html> </body>
</html>

Shri. Shambhubhai V. Patel College of CS and BM, Surat


Asst. Prof. Viral Patel PHP Database Program Subject: 504 Web Framework and Services

regEditData.php
<html>
<header>
</header>
<body>
<?php

if(isset($_GET['id']))
{
$conn = mysqli_connect("localhost","root","","mydb");
$sql = "select * from REGISTRATION where id=".$_GET['id'];
$res = mysqli_query($conn,$sql);
$row = mysqli_fetch_array($res);
?>
<form action="regDataUpdate.php">
<input type="hidden" name="uid" id="uid" value="<?php echo $row['id'];?>" readonly>
<table border="5px" style="margin:auto;border-collapse:collapse;">
<tr>
<td> </td>
<td> <b>Registration Page</b></td>
</tr>
<tr>
<td> Name:</td>
<td> <input type="text" name="nam" value="<?php echo $row['name'];?>"></td>
</tr>
<tr>
<td> Password:</td>
<td> <input type="password" name="pass1" value="<?php echo $row['pass'];?>"></td>
</tr>
<tr>
<td> Retype Password:</td>
<td> <input type="password" name="pass2" value="<?php echo $row['pass'];?>"></td>
</tr>

Shri. Shambhubhai V. Patel College of CS and BM, Surat


Asst. Prof. Viral Patel PHP Database Program Subject: 504 Web Framework and Services

<tr>
<td> Enter Mobile:</td>
<td> <input type="text" name="mob" value="<?php echo $row['mobile'];?>"></td>
</tr>
<tr>
<td> Select Course:</td>
<td>
<input type="radio" name="sub" value="BCA" <?php if($row['subject']=='BCA')echo "checked";?>>BCA
<input type="radio" name="sub" value="BBA" <?php if($row['subject']=='BBA')echo "checked";?>>BBA
<input type="radio" name="sub" value="BCOM" <?php if($row['subject']=='BCOM')echo "checked";?>>BCOM
</td>
</tr>
<tr>
<td> Select Hobbies:</td>
<td>
<input type="checkbox" name="hb1" value="1" <?php if($row['travelling']==1)echo "checked";?>>Travelling
<input type="checkbox" name="hb2" value="1" <?php if($row['sports']==1)echo "checked";?>>Sports
<input type="checkbox" name="hb3" value="1" <?php if($row['music']==1)echo "checked";?>>Music
</td>
</tr>
<tr>
<td> City:</td>
<td>
<select name="city" >
<option value="select">---select---</option>
<option value="surat" <?php if($row['city']=='surat')echo "selected";?>>surat</option>
<option value="ahmedabad" <?php if($row['city']=='ahmedabad')echo "selected";?>>ahmedabad</option>
<option value="bharuch" <?php if($row['city']=='bharuch')echo "selected";?>>bharuch</option>
<option value="baroda" <?php if($row['city']=='baroda')echo "selected";?>>baroda</option>
<option value="valsad" <?php if($row['city']=='valsad')echo "selected";?>>valsad</option>
</select>
</td>
</tr>

Shri. Shambhubhai V. Patel College of CS and BM, Surat


Asst. Prof. Viral Patel PHP Database Program Subject: 504 Web Framework and Services

<tr>
<td>Address:</td>
<td><textarea name="addr"><?php echo $row['address']; ?></textarea></td>
</tr>
<tr>
<td></td>
<td>
<input type="submit" name="btnupdate" value="update">
</td>
</tr>
</table>
</form>
<?php
}
?>
</body>
</html>
localhost/ty1/regEditData.php?id=1 localhost/ty1/regEditData.php?id=1

Shri. Shambhubhai V. Patel College of CS and BM, Surat


Asst. Prof. Viral Patel PHP Database Program Subject: 504 Web Framework and Services

regDeleteData.php
<?php

$conn = mysqli_connect("localhost","root","","mydb");

if(isset($_GET['id']))
{
$sql = "delete from REGISTRATION where id=".$_GET['id'];

mysqli_query($conn,$sql);

echo "record deleted successfully";


}

?>

Shri. Shambhubhai V. Patel College of CS and BM, Surat

You might also like