-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwrite.php
More file actions
27 lines (23 loc) · 739 Bytes
/
Copy pathwrite.php
File metadata and controls
27 lines (23 loc) · 739 Bytes
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
<?php
$servername = "localhost";
$username = "root";
$password = "";
$db ="chatapp";
// Create connection
$conn = new mysqli($servername, $username, $password, $db);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$username=substr($_GET["username"], 0, 32);
$text=substr($_GET["text"], 0, 360);
$nameescaped = htmlentities(mysqli_real_escape_string($conn,$username));
$textescaped = htmlentities(mysqli_real_escape_string($conn,$text));
$sql="INSERT INTO chat (username,text) VALUES ('$nameescaped','$textescaped')";
if ($conn->query($sql) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();
?>