Crud

Db.php
<?php
mysql_connect("localhost","root","");
mysql_select_db('crud');
echo "crud Database"
?>

             ======================================================
<?php
// Steps Edit
////////////////////Show data in the edit field
// 1 connection
// $id = $_GET['edit']; variable to get data from the last page from <a href="edit.php?edit=' $row['id']">edit</a>
//$query = mysql_query("select * from table where id='$id' ");
//catch data in $row = mysql_fetch_array($query);
//Show data in input field in value="<?php echo $row['id']; > "
///////////////
// Update data
// if(isset($_POST['update'])){
// set variable names $name=$_POST['name']; and phone etc
//$update = "update table set name ='$name' , phone='$phone' where id='$id' ";
// $result =mysql_query($update);
//}

include 'db.php';
echo "connection successful";

//"update user set name='$name', password='$pass' where id=$id ";

//$yasir = "update contact set name='$name' , phone='$phone' where id=$id";
$id = $_GET['edit'];
$yasir =mysql_query("select * from contact where id='$id' ");


$row = mysql_fetch_array($yasir);

if(isset($_POST['save']))
 {

$name = $_POST['name'];
$up = "update contact set name = '$name' where id = '$id' ";
$results =mysql_query($up);
echo "successfully updated";
}

?>         HTML for Edit
    <h1>Edit and Update Table</h1>
    <table class="table table-striped">
    <a href="show.php">Show data</a>
  <form action="" method="post">
     id:<input type="text" name="id" value="<?php echo $row['id']; ?>">
      Name:<input type="text" name="name" value="<?php echo $row['name']; ?>">
Phone:<input type="text" name="phone" value="<?php echo $row['phone']; ?>">
<input type="submit" name="save" value="Update">
</form>

=========================================================
Index php
                  <form action="" method="post">
Name:<input type="text" name="name">
Phone:<input type="text" name="phone">
<input type="submit" name="enter" value="submit">
</form>
<?php
include 'db.php';

if(isset($_POST['enter']))
{


$name = $_POST['name'];
$phone =$_POST['phone'];
echo $name;
echo $phone;
echo "<br />";
$in = "insert into contact(name,phone) values('$name','$phone')";
$q = mysql_query($in);

}
?>
==============================================================
Login .php
<form action="" method="post">

User Name:<input type="text" name="name">
Password:<input type="password" name="pass">
<input type="submit" name="enter" value="submit">
</form>


<?php
include 'db.php';
$name = $_POST['name'];
$pass = $_POST['pass'];

$check = mysql_query("select * from user where username='$name' and password='$pass' ");
$row=mysql_fetch_array($check);
 if($row['username']==$name & $row['password']==$pass){
  echo "login successfully ". $row['username'];
  header('Location: show.php');

 } else {
   echo "wrong user pass ";
  }

?>
=================================================================
Process php
<?php
// Get values pass from the form in login.php file

$username = $_POST['user'];
$password = $_POST['pass'];

// to prevent mysql injection
/*
$username = stripcslashes($username);
$password = stripcslashes($password);
$username = mysql_real_escape_string($username);
$password = mysql_real_escape_string($password);
*/

// connect to the server and select database
mysql_connect("localhost","root","");
mysql_select_db("login");

// Query the database for user

$result = mysql_query("select * from user where username='$username' and password='$password' ")
or die("Failed to query database ".mysql_error());

$row = mysql_fetch_array($result);

if ($row['username'] == $username & $row['password'] == $password  ) {
    echo "Login successful!!! Welcome" .$row['username'];
   
    header( 'Location: show.php' );

} else {
echo "Failed to login";
}

?>
==========================================================
search php
<?php
include 'db.php';

$search = $_POST['search'];

$find = mysql_query("select * from contact where name like '%$search%'  ");
echo  "The Record:".mysql_num_rows($find);
$row=mysql_fetch_array($find);
echo $row['name'];


/*


$yu=mysql_query("select * from customers where customerName like '$text%' ");

echo "The Record:".mysql_num_rows($yu);
}

while ($row =mysql_fetch_array($yu)) {
# code...
echo $row['customerName'];
}
?>
*/
?>
=====================================================
<?php
include 'db.php';


$query = "select * from contact";
$results = mysql_query($query);

<body>
    <h1>Hello, world!</h1>
    <form action="" method="post">
      Name: <input type="text" name="name"><br />
      <input type="submit" value="Enter" name="enter">
</form>
<h1> List of Companies</h1>
<a href="" onclick="return confirm('Are you sure you want to delete this item?');">Delete</a>
<?php 
            
echo "<table class=\"table table-striped\">
      <tr>
            <th>ID</th>
            <th>Name</th>
            <th>Name</th>
            <th>Edit</th>
            <th>Delete</th>
            </tr>";

while($row = mysql_fetch_array($results)) {
echo "<tr>";
echo "<td>". $row['id'] ."</td>" ;
echo "<td>". $row['name'] ."</td>" ;
echo "<td>". $row['phone'] ."</td>"  ;
//echo "edit.php?id=".$row['id']"";
//echo "<a href='edit.php?edit=" . $row['id']. "'>Edit</a>";
echo  "<td>"." <a href='edit.php?edit=$row[id]'>edit</a>" ."</td> ";
echo  "<td>". "<a href='delete.php?delete=$row[id]'>Delete</a>". "</td>";
echo "</tr>";
}

?>
================================================================
Template 

<!DOCTYPE html>
<html>
<head>
<title>Admin</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body background-image="s">

<div id="header">
IRICH ADMISSIONS Processer
</div>
<div id="container">
     <h1>The Great Container</h1>
<div id="sidebar">
<nav>
<a href="index.php"><li>Home</li></a>
<a href="post.php"><li>Add Post</li></a>
<a href="admin.php"><li>Add Admin</li></a>
<a href="view-admin.php"><li>View Admin</li></a>
<a href="delete.php"><li>Delete Post</li></a>
</nav>
</div>
<div id="main">
</div>
<div id="empty">
</div>
</div>
<div id="footer">
footer
</div>

</body>
</html>
============================================================
style .css for template 
*{
margin:0;
padding:0;
/*background-image: url("blue_candle.jpg"); */
}
#header{
background-color:#eee; 
width: 960px;
height:200px ;
margin-left: auto;
margin-right: auto;

}
#container {
background-color: blue;
width: 960px;
height: 200px;
margin-left: auto;
margin-right: auto;
}
#sidebar{
background-color: navy;
width: 360px;
height: 200px;
float: left;

}
#main{
background-color: skyblue;
width: 600px;
height: 200px;
float: left;
}
.empty{
clear: both;
}
#footer{
width: 960px;
margin-left: auto;
margin-right: auto;
}

Comments

Popular posts from this blog

Complete Php

apple