Web Applications Development

PHP

MySQL Update in PHP using Form Data

 Gets the data as form data from the browser when user enters values

<html>
<head></head><body><form action="update.php" method="GET">ID <input type="text" name="id"><br>
Name <input type="text" name="name"><br>
Password <input type="text" name="pw"><br>
New Password <input type="text" name="npw"><br>
<input type="submit"></form></body></html>
dbcon.php
Establish the Connection with the database
<?php
$server="localhost";
$uname="root";
$pw="";
$dbname="testdb";$conn= mysqli_connect($server,$uname,$pw,$dbname);if ($conn->connect_error) {die("Connection failed: " . $conn->connect_error);}?>
update.php
File which is included SQL query
<?php
include_once 'dbcon.php'
?><?php$sql = "UPDATE users SET password = '".$_GET['npw']."' WHERE id =".$_GET['id']." AND password='".$_GET['pw']."'";if ($conn->query($sql) === TRUE) {
    echo "Record Updated successfully";
} else {
    echo "Error updating record: " . $conn->error;
}$conn->close();
?>

MySQL Delete  in PHP 

index.html

Gets the Id as form data from the browser when user enters a value 
   
<html>

<head>
    <Title>Delete</Title>
</head>

<body>
    <form action="delete.php" method="GET">
        Enter ID of the user You need to Download <input type="text" name="id"><br>
        <input type="submit">
    </form>
</body>

</html>


dbcon.php

Establish the Connection with the database

<?php

$server="localhost";
$uname="root";
$pw="";
$dbname="testdb";

$connmysqli_connect($server,$uname,$pw,$dbname);

if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
?>

delete.php

File which is included SQL query

<?php
include_once 'dbcon.php'
?>

<?php

$sql = "DELETE FROM users WHERE id=".$_GET["id"];

if ($conn->query($sql) === TRUE) {
    echo "Record deleted successfully";
else {
    echo "Error deleting record: " . $conn->error;
}

$conn->close();
?>

No comments:

Post a Comment

Popular Posts