Last active
January 10, 2017 07:51
-
-
Save incubs/f2c9aa6dca90a25bc3c702284abf34e6 to your computer and use it in GitHub Desktop.
data delete and update
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// this is to show the data from database ,list page | |
//form list page | |
{ | |
//echo "show"; | |
$mysql = mysqli_connect('localhost', 'root', '', 'leapfrog'); | |
$query = "select * from users"; | |
$result = mysqli_query($mysql, $query); | |
//echo $result; | |
// while($row = mysqli_fetch_assoc($result)){ | |
?> | |
<div class="container"> | |
<table class="table-condensed table-bordered table-hover"> | |
<?php $i = 0; | |
while ($row = mysqli_fetch_assoc($result)) { ?> | |
<tr> | |
<?php | |
// $row = mysqli_fetch_assoc($result); | |
if (!empty($row) and ($i == 0)) { | |
foreach ($row as $tablehead => $value) { | |
?> | |
<th> | |
<?php | |
echo $tablehead; | |
?> | |
</th> | |
<?php $i++; | |
} | |
} | |
?> | |
</tr> | |
<!-- --><?php //while($row = mysqli_fetch_assoc($result)) {?> | |
<tr> | |
<?php | |
if (!empty($row)) { | |
foreach ($row as $value) { | |
?> | |
<td> | |
<?php if (!empty($value)) { | |
if (is_array($value)) { | |
foreach ($value as $item) { | |
echo $item; | |
} | |
} else { | |
echo $value; | |
} | |
} ?></php> | |
</td> | |
<?php | |
} ?> | |
<td> | |
<div class="form-group" > | |
<a href="delete.php?id=<?php echo $row['id'];?>" class="btn btn-info">Delete</a> | |
</div> | |
</td><td> | |
<div class="form-group" > | |
<a href="update.php?id=<?php echo $row['id'];?>" class="btn btn-info"> Update</a> | |
</div> | |
</td> | |
<?php } | |
?> | |
</tr> | |
<?php } ?> | |
</table> | |
</div> | |
<?php | |
// } | |
} | |
// for deleting the data | |
<?php | |
$mysql=mysqli_connect('localhost','root','','leapfrog'); | |
$query="delete from users where id=".$_GET['id']; | |
mysqli_query($mysql,$query); | |
header("location:formlist.php"); | |
//for updating data form in updating mode | |
<?php | |
$id=$_GET['id']; | |
$mysql=mysqli_connect('localhost','root','','leapfrog'); | |
$query="select * from users where id=".$id; | |
$result=mysqli_query($mysql,$query); | |
$row = mysqli_fetch_assoc($result); | |
if (!empty($row)){ | |
?> | |
<html> | |
<head> | |
<title>Form</title> | |
<link rel="stylesheet" href="css/bootstrap.css"> | |
</head> | |
<body> | |
<div class="container"> | |
<div class="row"> | |
<h1>Form</h1> | |
<form action="confirmupdate.php" class="form" method="get"> | |
<div class="form-group"> | |
<label for="name">Name</label> | |
<input type="text" name="name"class="form-control" value="<?php echo $row['name']; ?>"> | |
</div> | |
<div class="form-group"> | |
<label for="password">Password</label> | |
<input type="password" name="password" class="form-control" value="<?php echo $row['password']; ?>"> | |
</div> | |
<div class="form-group"> | |
<label for="message">Message</label> | |
<textarea name="message" id="" cols="30" rows="10" class="form-control"><?php echo $row['message']; ?></textarea> | |
</div> | |
<div class="form-group" > | |
<input name="id" type="hidden" value="<?php echo $id ?>"/> | |
<button class="btn btn-info" name="update" >Update</button> | |
</div> | |
</form> | |
</div> | |
</div> | |
</body> | |
</html> | |
<?php } ?> | |
// finally for updating the changes | |
<?php | |
if (isset($_GET['update'])) { | |
$mysql = mysqli_connect('localhost', 'root', '', 'leapfrog'); | |
$name = $_GET['name']; | |
$message = $_GET['message']; | |
$password = $_GET['password']; | |
$id = $_GET['id']; | |
$query = "update users set name='$name',message='$message',password='$password' where id='$id'"; | |
mysqli_query($mysql, $query); | |
header("location:formlist.php"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment