ajax_php2

 <?php

$con=mysqli_connect("localhost","root","","student")
or die("not connected");
<?php
include "sql_connect.php";
$name=$_REQUEST['nm'];
$pass=$_REQUEST['pwd'];

// echo $name;
// echo $pass;
if(isset($name) &&isset($pass)){
    $sql_query="insert into student_record(name,pwd) values('{$name}','{$pass}')";

$query=mysqli_query($con,$sql_query) or die("not executing");
if($query){
    echo 1;
}
else{
    echo 0;
}


}




?>
.................delete.................
<?php
include "sql_connect.php";
$nm1=$_REQUEST['nm'];

$sql_query="delete from student_record where name='{$nm1}'";
$query=mysqli_query($con,$sql_query) or die("not executing");

if($query){
    echo 1;
}



?>
..........edit..................
<?php
include "sql_connect.php";
$name=$_REQUEST['nm'];
//echo $name;
 $sql_query="select * from Student_record where name='$name'";
 //echo $sql_query;
$result=mysqli_query($con,$sql_query) or die("not executing");
$r_count=mysqli_num_rows($result);
//echo $r_count;
if($r_count>0){
    ?>
<table>
    <?php
    while($data=mysqli_fetch_assoc($result)){
?>
<tr><td><label for="name">Name</label></td>
<td><input type="text" id='nme' value=<?php echo $data['name']; ?> readonly> </td></tr>
<tr><td><label for="password">Password</label></td><td><input type=text  id='pwe' value=<?php echo $data['pwd']; ?>></td>
    </tr>
    <tr><td colspan="2"  align="center"><button class="sav" data-name=<?php  echo $data['name'] ?>>Save</td></tr>
    <!-- data-pwd=<?php echo $data['pwd'] ?> -->

<?php
    }
}


?>
....................read..........

<!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>
    <link rel="stylesheet" href="style/style.css">
</head>
<body>
<?php
include "sql_connect.php";
$sql_query="select * from student_record";
$result=mysqli_query($con,$sql_query) or die("not executing");
$r_count=mysqli_num_rows($result);
//echo $r_count;
if($r_count>0){
    ?>
    <table><tr><th>NAME</th><th>Password</th><th>Actions</th></tr>
<?php
    while($data=mysqli_fetch_assoc($result)){
?>
<!-- https://www.w3schools.com/tags/att_data-.asp -->
<tr><td><?php echo $data['name'] ?></td>
<td><?php echo $data['pwd']  ?></td>
<?php $nm=$data['name'] ?>
<td><button data-name=<?php echo $nm; ?>  class='del' >Delete</button></td>
<td><button data-name=<?php echo $nm; ?> class='edit'>Edit</button></td>
    </tr>
<?php
    }?>
    </table>
    <?php
}
?>
 
</body>
</html>






Comments

Popular posts from this blog

interview questions js[ Anurag Singh ProCodrr]

reactnative_creation