-
Notifications
You must be signed in to change notification settings - Fork 0
/
insert.php
73 lines (53 loc) · 2.05 KB
/
insert.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
// include_once 'database-con.php';
// if(isset($_POST['save']))
// {
// $cname = $_POST['cname'];
// $email = $_POST['email'];
// $subjects = $_POST['subjects'];
// $messages = $_POST['messages'];
// $sql = "INSERT INTO message(cname,email,subjects,messages)
// VALUES ('$cname','$email','$subjects','$messages')";
// if (mysqli_query($conn, $sql)) {
// echo "New record has been added successfully !";
// } else {
// echo "Error: " . $sql . ":-" . mysqli_error($conn);
// }
// mysqli_close($conn);
// }
// include "database-con.php";
// if (isset($_POST['cname']) && isset($_POST['email']) && isset($_POST['subjects']) && isset($_POST['messages'])) {
// $cname = $_POST['cname'];
// $email = $_POST['email'];
// $subjects = $_POST['subjects'];
// $messages = $_POST['messages'];
// $sql = "INSERT INTO message(cname,email,subjects,messages)
// VALUES('$cname','$email','$subjects','$messages')";
// if (mysqli_query($conn, $sql)) {
// echo "New record has been added successfully !";
// } else {
// echo "Error: " . $sql . ":-" . mysqli_error($conn);
// }
// mysqli_close($conn);
// }
$link = mysqli_connect("localhost", "root", "", "shakiliitju");
// Check connection
if($link === false){
die("ERROR: Could not connect. " . mysqli_connect_error());
}
// Escape user inputs for security
$cname = mysqli_real_escape_string($link, $_REQUEST['cname']);
$email = mysqli_real_escape_string($link, $_REQUEST['email']);
$subjects = mysqli_real_escape_string($link, $_REQUEST['subjects']);
$messages = mysqli_real_escape_string($link, $_REQUEST['messages']);
// Attempt insert query execution
$sql = "INSERT INTO message(cname, email, subjects, messages) VALUES ('$cname', '$email','$subjects','$messages')";
if(mysqli_query($link, $sql)){
echo "Thank You 😍";
echo " Message send successfully.";
} else{
echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
}
// Close connection
mysqli_close($link);
?>