-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinsert.php
38 lines (30 loc) · 1.06 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
<?php
include 'includes/connections.php';
//$message = "<h4>You said:</h4><p>testing from php file</p>";
$message = $_POST['message'];
$realMessage = mysql_real_escape_string($message);
$labledMessage = "<h4>You said:</h4><p>" . $realMessage . "</p>";
//adding most recent message to database
$insertQuery = "INSERT INTO messages (messages) VALUES ('" . $labledMessage . "')";
if (!mysql_query($insertQuery, $con)) {
die('Error: ' . mysql_error($con));
}
//pulling all messages after adding most recent
$result1 = mysql_query("SELECT messages FROM messages ORDER BY id DESC", $con);
//printing only the messages that are new
/* $recent = mysql_fetch_array($result1, MYSQL_ASSOC);
$length = count($recent);
for($i=0; $i<$length; $i++){
if($recent[$i] != $_SESSION['mostRecent']){
echo $recent['messages'];
}
else if ($recent == $_SESSION['mostRecent']){
echo $recent['messages'];
return;
}
}*/
//printing ALL messages in db to the screen
while($extract = mysql_fetch_array($result1, MYSQL_ASSOC)){
echo $extract['messages'] . "<br />";
}
?>