Complete Php

Db.php 


<?php
$host = "localhost";
$user = "root";
$pass = "";
$db   = "practice";

$link =mysqli_connect($host,$user,$pass,$db)
or die(mysqli_error());
if($link)
{
echo "Database Connected Successfully";
}
else {
echo "Not Connected with a database";
}


?>

insert.php


<?php
include 'db.php';

$phone = $_POST['phone'];
$sql =mysqli_query($link,"insert into user (phone) values ('$phone')  ");


?>


<hr>
Welcome to insert page
<br>


<a href="logout.php">Logout</a><a href="show.php">show php</a>
<form method="post" action="">
Phone<input type="text" name="phone" >
<input type="submit">
</form>

Show.php with Edit starts here

<?php
include 'db.php';

$sql = ("select * from user ");
$result =mysqli_query($link,$sql);

while($row=mysqli_fetch_array($result)) {
echo $row['id'] ."...". $row['phone']; 

//id=row is a variable and can be any name like abc,xyz 

echo " <a href='edit.php?id=$row[id] ' >Edit </a>";
echo "<br>";
}

?>

Edit.php First Step Show edit


<?php
include 'db.php';

$id = $_GET['id']; // this id inside $_Get is the variable from show page

$sql = "select * from user where id='$id' ";
$result = mysqli_query($link,$sql);

$row=mysqli_fetch_array($result);

//$sql = "update user set phone where id='$id' "; 


$phone =$_POST['phone'];
$sql = "update user set phone='$phone' where id='$id' ";
$result =mysqli_query($link,$sql) or die(mysql_error()); 


?>

<hr>
Welcome to Edit page
<br>


<a href="logout.php">Logout</a><a href="show.php">show php</a>
<form method="post" action="">
Phone<input type="text" name="phone" value="<?php echo $row['phone']; ?> " >
<input type="submit">
</form>








Comments

Popular posts from this blog

Crud

apple