0% found this document useful (0 votes)
8 views4 pages

MAN

This PHP script connects to a MySQL database and handles form submissions for user information. It validates input fields to prevent SQL injection and performs operations such as inserting new records, deleting specific records, and updating existing records in the database. Error handling is included to provide feedback on the success or failure of these operations.

Uploaded by

arthurtsapi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views4 pages

MAN

This PHP script connects to a MySQL database and handles form submissions for user information. It validates input fields to prevent SQL injection and performs operations such as inserting new records, deleting specific records, and updating existing records in the database. Error handling is included to provide feedback on the success or failure of these operations.

Uploaded by

arthurtsapi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

<?

php

// db

$servername = "localhost";

$username = "root";

$password = "";

$dbname = "tp";

// Database connexion

$conn = new mysqli($servername, $username, $password, $dbname);

// Check connexion

if ($conn->connect_error) {

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

// Fonction de validation pour éviter les injections SQL

function test_input($data) {

$data = trim($data);

$data = stripslashes($data);

$data = htmlspecialchars($data);

return $data;

// var_dump($dbname);

$name= $speciality=$address=$email=$date="";

$nameErr= $specialityErr=$addressErr=$emailErr=$dateErr="";

if ($_SERVER["REQUEST_METHOD"] == "POST") {

// $name=test_input($_POST["name"]);

// $speciality=test_input($_POST["speciality"]);

// $address=test_input($_POST["Address"]);

// $email=test_input($_POST["email"]);
// $date=test_input($_POST["date"]);

if (empty($_POST["name"])) {

$nameErr = "Name is required";

} else {

$name = test_input($_POST["name"]);

if (empty($_POST["email"])) {

$emailErr = "Email is required";

} else {

$email = test_input($_POST["email"]);

if (empty($_POST["speciality"])) {

$specialityErr = "speciality is required";

} else {

$speciality = test_input($_POST["speciality"]);

if (empty($_POST["date"])) {

$dateErr = "date is required";

} else {

$date = test_input($_POST["date"]);

if (empty($_POST["Address"])) {

$addressErr = "address is required";

} else {

$address = test_input($_POST["Address"]);
}

$sql = "INSERT INTO info (Email, Name, Address,Speciality,Date)

VALUES ('$email',' $name', '$address', '$speciality','$date')";

if ($conn->query($sql) === TRUE) {

echo "New record created successfully";

} else {

echo "Error: " . $sql . "<br>" . $conn->error;

$request1= "DELETE FROM info where Speciality='COMPUTER GRAPGICS'";

if ($conn->query($request1) === TRUE) {

echo "deleted successfully";

} else {

echo "Error: " . $request1 . "<br>" . $conn->error;

$request2= "UPDATE info SET Address ='yaounde' where Address='BONABERI'";

if ($conn->query($request2) === TRUE) {

echo "update successfully";

} else {

echo "Error: " . $request2 . "<br>" . $conn->error;

$conn->close();

}
?>

You might also like