-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.php
69 lines (59 loc) · 2.07 KB
/
index.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
<?php
//require_once("credentials.php");
/* Attempt MySQL server connection. Assuming you are running MySQL
server with default setting (user 'root' with no password) */
//echo $HOSTNAME;
$link = mysqli_connect(getenv('HOSTNAME'),getenv('ROOT_USERNAME'),getenv('ROOT_PASSWORD'),getenv('DB_NAME'));
//$link = mysqli_connect("192.168.43.225","root","ajay","mydb");
// Check connection
if($link === false){
die("ERROR: Could not connect. " . mysqli_connect_error());
}
$show_result="select * from records";
$result= mysqli_query($link,$show_result);
// Attempt insert query execution
if(isset($_POST["message"])){
$message=$_POST["message"];
$sql = "INSERT INTO records (message) VALUES ('$message')";
if(mysqli_query($link, $sql)){
echo '<script>alert("Records inserted successfully")</script>';
} else{
echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
}
//$show_result="select * from records";
//$result= mysqli_query($link,$show_result);
// Close connection
//mysqli_close($link);
//
}
?>
<html>
<head>
<title>Hello!</title>
</head>
<body style="font-family: Verdana,Tahoma,sans-serif">
<h2>Welcome to MyApp! Post a message to the board using the form at the bottom!</h2>
<div style="border: 1px solid #BBB; padding: 5px; font-weight: bold; font-size: small">
Message Board
</div>
<div style="border-left: 1px solid #BBB; border-right: 1px solid #BBB; border-bottom: 1px solid #BBB; padding: 5px; font-size: small">
<?php
if(mysqli_num_rows($result) == 0)
echo "No records in database!";
else
{
while($row = mysqli_fetch_array($result, MYSQLI_ASSOC))
echo "{$row['message']}<br />";
}
?>
</div>
<form name="message" action="" method="POST" style="padding-top: 15px">
Message:<br />
<input type="text" name="message" style="length: 300px" />
<input type="submit" name="submit" value="Submit" />
</form>
<div style="font-size: small; font-size: small; font-color: #DDD">
Served from <?php echo `hostname`; ?>.
</div>
</body>
</html>