0% found this document useful (0 votes)
23 views

PHP Databaseupdate

The document describes a student registration form and database that stores form submissions. It includes PHP code examples to create a database and table, insert form data, and retrieve and display the stored registration records.

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)
23 views

PHP Databaseupdate

The document describes a student registration form and database that stores form submissions. It includes PHP code examples to create a database and table, insert form data, and retrieve and display the stored registration records.

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/ 11

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 regDataUpdate.php
<html> <?php
<header> $conn = mysqli_connect("localhost","root","","mydb");

</header>
if(isset($_GET['btnupdate']))
<body>
{
<?php
$uid = $_GET['uid'];
$nm = $_GET['nam'];
if(isset($_GET['id']))
$p1 = $_GET['pass1'];
{
$p2 = $_GET['pass2'];
$conn = mysqli_connect("localhost","root","","mydb");
$mb = $_GET['mob'];
$sql = "select * from REGISTRATION where id=".$_GET['id'];
$sb = $_GET['sub'];
$res = mysqli_query($conn,$sql);
if(isset($_GET['hb1'])) $h1 = B'1';
$row = mysqli_fetch_array($res);
else $h1 = B'0';
?>
if(isset($_GET['hb2'])) $h2 = B'1';
<form action="regDataUpdate.php">
else $h2 = B'0';
<input type="hidden" name="uid" id="uid" value="<?php echo $row['id'];?>" readonly>
if(isset($_GET['hb3'])) $h3 = B'1';
<table border="5px" style="margin:auto;border-collapse:collapse;">
else $h3 = B'0';
<tr>
$ct = $_GET['city'];
<td> </td>
$ad = $_GET['addr'];
<td> <b>Registration Page</b></td>
</tr>
$sql = "update REGISTRATION set
<tr>
name = '$nm', pass = '$p1',
<td> Name:</td>
mobile = '$mb', subject = '$sb',
<td> <input type="text" name="nam" value="<?php echo $row['name'];?>"></td>
travelling = $h1, sports = $h2,
</tr>
music = $h3, city = '$ct',
<tr>
address = '$ad' where id=".$uid;
<td> Password:</td>
//print_r($sql);
<td> <input type="password" name="pass1" value="<?php echo $row['pass'];?>"></td>
mysqli_query($conn,$sql);
</tr>
echo "record updated successfully";
<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


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

regDispColumnNames.php //-------display data (all rows of table)-----------------------------------


<html>
<body> $sql = "select * from REGISTRATION";

<?php $res = mysqli_query($conn,$sql);


$conn = mysqli_connect("localhost","root","","mydb");
while($row=mysqli_fetch_array($res))
echo "<table border=1>"; {
echo "<tr>";
//---display columns name as first row in table---------------------------- for($i=0;$i<10;$i++)
{
$sql = "SHOW COLUMNS FROM registration"; echo "<td>$row[$i]</td>";
}
$result = mysqli_query($conn,$sql); echo "<td><a href='regEditData.php?id=$row[0]'>edit</a></td>";
echo "<td><a href='regDeleteData.php?id=$row[0]'>delete</a></td>";
echo "<tr>"; echo "</tr>";
while($row = mysqli_fetch_array($result)) }
{
echo "<td><b>".$row['Field']."<b></td>"; echo "</table>";
} ?>
echo "<td></td><td></td>";
echo "</tr>"; </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

regDispColumnOrder.php //----add order by in select query------


<html> if(isset($_GET['col']))
<body> {
<?php $sql = $sql." order by ".$_GET['col'];
}
$conn = mysqli_connect("localhost","root","","mydb");
$res = mysqli_query($conn,$sql);
//--- put link on column name for ordering data ----------------------- while($row=mysqli_fetch_array($res))
{
$sql = "SHOW COLUMNS FROM registration"; echo "<tr>";
$result = mysqli_query($conn,$sql); for($i=0;$i<10;$i++)
{
echo "<table border=1>"; echo "<td>$row[$i]</td>";
echo "<tr>"; }
while($row = mysqli_fetch_array($result)) echo "<td>";
{ echo "<a href='regEditData.php?id=$row[0]'>edit</a>";
echo "<td><b>"; echo "</td>";
echo "<a href='regDispColumnOrder.php?col=".$row['Field']."'>".$row['Field']."</a>"; echo "<td>";
echo "<b></td>"; echo "<a href='regDeleteData.php?id=$row[0]'>delete</a>";
} echo "</td>";
echo "<td></td><td></td>"; echo "</tr>";
echo "</tr>"; }
echo "</table>";
//------- display data (all rows of table) ------------------------------------ ?>
</body>
$sql = "select * from REGISTRATION"; </html>

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

You might also like