-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinsertgame.php
41 lines (36 loc) · 869 Bytes
/
insertgame.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
<!doctype html>
<html>
<head>
<title>Insert scores into database</title>
</head>
<body>
<?php
// chech for inputs
if(!isset($_POST['gametag'])){
echo "<p>Not enough info</p>";
exit;
}
//create short variable names
$gametag=strtolower(trim($_POST['gametag']));
$fname=$_POST['fname'];
$car=$_POST['car'];
$score=$_POST['score'];
//begin database session
@$db=new mysqli('localhost', 'u856159605_quiz', 'Amand@l0ve', 'u856159605_quiz');
if(mysqli_connect_errno()){
echo '<p>Error. Cannot connect to the database</p>';
exit;
}
$query="INSERT INTO scoreboard (gametag, fname, car, score) VALUES (?, ?, ?, ?)";
$stmt=$db->prepare($query);
$stmt->bind_param('ssss', $gametag, $fname, $car, $score);
$stmt->execute();
if($stmt->affected_rows > 0){
echo '<p>Thank you for playing!</p>';
}else{
echo '<p>ooops!</p>';
}
$db->close();
?>
</body>
</html>