php sql
<?php
$con = mysqli_connect("localhost", "root", "", "employee") or die("not connect");
// if (isset($con)) {
// echo "this is connected";
// }
insert:
<?php
include "sql_connect.php";
$name = $_GET["nm"];
$pass = $_GET["pwd"];
//$name = "tskr";
//$pass = "123";
//echo $name . "" . $pass;
if (isset($name) && isset($pass)) {
$sql_query = "INSERT INTO student_record (NAME, PASSWORD)
VALUES ('{$name}','{$pass}')";
//echo $sql_query;
//return $sql_query;
$query = mysqli_query($con, $sql_query) or die("not executing");
//if(mysqli_query($con,$sql_query))
if ($query) {
// echo 'data inserted sucessfully';
//definet..we use ajax..
// header("")
// return 1;
echo 1;
} else {
//return 0;
echo 0;
}
}
mysqli_close($con);
<?php
include "sql_connect.php";
$sql_query = "select * from student_record ";
//run...
$result = mysqli_query($con, $sql_query) or die("not executing");
$r_count = mysqli_num_rows($result);
//echo $r_count;
if ($r_count > 0) {
$show_data = '<table border="1px" width="100%">
<tr><th>Name</th><th>password</th></tr>';
while ($data = mysqli_fetch_assoc($result)) {
//echo var_dump($data);
$show_data .= "<tr>
<td> {$data['NAME']}</td>
<td>{$data['PASSWORD']}</td>
<td><button data-name={$data['NAME']} class='del'>Delete </button></td>
<td><button data-name={$data['NAME']} class='edit'>Edit </button></td>
<tr>";
}
// data-* attribute give us the ability to embeded
// custom data attributes on all HTML elements
$show_data .= "</table>";
echo $show_data;
} //else {
// echo "data not found";
// }
mysqli_close($con); ?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<style>
</style>
<body>
</body>
</html>
Update:
<?php
include "sql_connect.php";
$name = $_GET['nm'];
$password = $_GET['pwd'];
$sql_query = "UPDATE student_record SET NAME='{$name}' WHERE NAME='peter1'";
$query = mysqli_query($con, $sql_query) or die("not working");
if ($query) {
echo "updated";
}
mysqli_close($con);
Delete:
<?php
include "sql_connect.php";
$name = $_GET['nm'];
//
$sql_query = "delete from student_record where NAME='{$name}' ";
$query = mysqli_query($con, $sql_query) or die("not working");
if ($query) {
echo 1;
}
mysqli_close($con);
Comments
Post a Comment