0% found this document useful (0 votes)
9 views4 pages

Query

The document contains PHP code for a web application that manages user registrations, including functionalities for inserting, updating, and deleting user records. It connects to a MySQL database and provides a form for user input, displaying messages based on the success or failure of operations. The code also includes a confirmation dialog for deletions and dynamically populates the form with user data for editing purposes.

Uploaded by

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

Query

The document contains PHP code for a web application that manages user registrations, including functionalities for inserting, updating, and deleting user records. It connects to a MySQL database and provides a form for user input, displaying messages based on the success or failure of operations. The code also includes a confirmation dialog for deletions and dynamically populates the form with user data for editing purposes.

Uploaded by

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

FORM

<?php
include("connection.php");
if(isset($_REQUEST['inserted'])){
$msg=$_REQUEST['inserted'];
if($msg == 'yes'){
echo "<div style='color:green'>Inserted...</div>";
}else{
echo "<div style='color:red'>Not Inserted...</div>";
}
}

if(isset($_REQUEST['updated'])){
$msg=$_REQUEST['updated'];
if($msg == 'yes'){
echo "<div style='color:green'>updated...</div>";
}else{
echo "<div style='color:red'>Not updated...</div>";
}
}

if(isset($_REQUEST['deleted'])){
$msg=$_REQUEST['deleted'];
if($msg == 'yes'){
echo "<div style='color:green'>deleted...</div>";
}else{
echo "<div style='color:red'>Not deeted...</div>";
}
}

$editName="";
if(isset($_REQUEST['editid']))
{
$id=$_REQUEST['editid'];
$query="select * from registration where user_id=".$id;
$editRes=mysqli_query($con,$query);

$editRow=mysqli_fetch_array($editRes);
$editName=$editRow['user_name'];
//print_r($editRow);
// echo $editName;
// return;
}

?>
<html>
<head>
<style>
table,tr,td,th{
border: 1px solid black;
}
</style>
<script>
function conDelete()
{
var yesno=confirm("Are You Sure You Want To Delete ?");
if(yesno)
{
return true;
}else{
return false;
}
}
</script>
</head>
<body>
<?php
if(isset($_REQUEST['editid'])){
$id=$_REQUEST['editid'];
echo '<form name="frm" method="get" action="update.php">';
echo "<input type=\"hidden\" name=\"hdnId\" value=\"$id\" />";
}else{
echo '<form name="frm" method="get" action="getData.php">';
}
?>

Name:<input type="text" name="txtName" value="<?php echo $editName; ?


>"/>
<br>
<?php
if(isset($_REQUEST['editid'])){
echo '<input type="submit" name="btn" value="Update"/>';
}else{
echo '<input type="submit" name="btn" value="Insert"/>';
}
?>

</form>
</body>
</html>
<table>
<th>Sr.No</th>
<th>User Id</th>
<th>User Name</th>
<th>Edit</th>
<th>Delete</th>
<?php
$query="select * from registration";
$res=mysqli_query($con,$query);
$i=1;
while($row=mysqli_fetch_object($res))
{
echo "<tr>";
echo "<td>".$i++."</td>";
echo "<td>".$row->user_id."</td>";
echo "<td>".$row->user_name."</td>";
echo "<td><a href='form.php?editid=".$row->user_id."'>Edit</a></td>";
echo "<td><a href='delete.php?delete=".$row->user_id."' onclick='return
conDelete();'>delete </a></td>";
echo "</tr>";
/* print_r($row);
echo "<br>"; */
}

?>

</tr>
</table>

GETDATA

<?php
include("connection.php");
$name=$_REQUEST['txtName'];

$query="insert into registration(user_name) values('$name')";

$len=mysqli_query($con,$query);
if($len > 0){
header("Location:form.php?inserted=yes");
}else{
header("Location:form.php?inserted=no");
}
?>

CONNECTION

<?php
$con=mysqli_connect("localhost","root","") or die("problem in connection...");
$db=mysqli_select_db($con,"tybca6");

?>

UPDATE

<?php
include("connection.php");
//print_r($_REQUEST);
$id=$_REQUEST['hdnId'];
$name=$_REQUEST['txtName'];
//echo $name;
$query="Update registration set user_name='$name' where user_id=$id";

//echo $query;
$len=mysqli_query($con,$query);
if($len > 0){
header("Location:form.php?updated=yes");
}else{
header("Location:form.php?updated=no");
}

?>

DELETE
<?php
include("connection.php");
$id=$_REQUEST['delete'];
$query="delete from registration where user_id=".$id;

$len=mysqli_query($con,$query);
if($len > 0){
header("Location:form.php?deleted=yes");
}else{
header("Location:form.php?deleted=no");
}

?>

You might also like