-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcondb.php
60 lines (51 loc) · 1.32 KB
/
condb.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
<html>
<head>
<title>
Connection to a database
</title>
</head>
<body>
<?php
$con=mysqli_connect('localhost','root','');
$db=mysqli_select_db($con,'Prodigy');
if($con){
echo 'Successfully connnected to the database.';
}
else{
die('Error.');
}
if($db){
echo 'Successfully found the database.';
}
else{
die('Error. database not found');
}
?>
<br>
<br>
<?php
// Escape user inputs for security
$question = mysqli_real_escape_string($con, $_REQUEST['ques']);
$code = mysqli_real_escape_string($con, $_REQUEST['code']);
// attempt insert query execution
if(mysqli_query($con, "INSERT INTO code (ques,code) VALUES ('$question', '$code')")){
echo "Records added successfully.";
} else{
echo "ERROR: Could not able to execute " . mysqli_error($con);
}
// close connection
mysqli_close($con);
?>
<br>
<br>
<?php
$query=mysqli_query($con,"SELECT * FROM code");
while($row=mysqli_fetch_array($query)){
$snum=$row['s.no.'];
$question=$row['ques'];
$code=$row['code'];
echo $snum.':'.$question.'<br>'.$code;
}
?>
</body>
</html>