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 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
|
<?php
$bdd = new PDO('mysql:host=localhost;dbname=espace_membre', 'root', '');
if(isset($_POST['validate'])) {
$answer = htmlspecialchars($_POST['answer']);
if(!empty($_POST['answer'])){
$answerlength = strlen($answer);
if($answerlength <= 255) {
if($answer == 3) {
$erreur = "Right answer";
$id = //Mets ici le code pour reprendre la session de l'utilisateur et donc, son id
$points = $bdd->exec('SELECT points FROM tadb WHERE id = '.$id.'');
$newpoints = ($points + 1);
$insertpoints = $bdd->exec('INSERT INTO `tadb`(`points`) VALUES ('.$newpoints.')');
}
else {
$erreur = "Wrong answer" ;
}
} else {
$erreur = "Your answer must not exceed 255 print";
}
} else {
$erreur = "Your answer is empty";
}
}
?>
<html>
<head>
<meta charset="utf-8" />
<title>Solving problem</title>
</head>
<body style="background-color: #FFD700; text-align: center;" >
<div>
<h1> Recent problems to solve </h1>
<div>
<p> <TABLE BORDER="1" style="margin: auto; width: 1000px; height: 900px;">
<TR>
<TH> </TH>
<TH> Name </TH>
<TH> Age </TH>
<TH> Country </TH>
<TH> Problem </TH>
<TH> Answer to the problem </TH>
</TR>
<TR>
<TH> Problem 1 </TH>
<TD> </TD>
<TD> </TD>
<TD> </TD>
<TD> </TD>
<TD style="width: 200px; height: 276px;">
<form action="" method="POST">
<label for="answer">Your solution :</label>
<input type="text" placeholder="Your answer" id="answer" name="answer" value="<?php if (!empty($answer)) { echo $answer; } ?>" />
<br />
<input type="submit" name="validate" value="Validate my answer" />
<?php
if(isset($erreur)) {
echo '<font color="red">'.$erreur."</font>";
}
?>
</TD>
</TR>
</form>
<TR>
<TH> Problem 2 </TH>
<TD> </TD>
<TD> </TD>
<TD> </TD>
<TD> </TD>
<TD>
<form action="" method="POST">
<label for="answer">Your solution :</label>
<input type="text" placeholder="Your answer" id="answer" name="answer" value="<?php if(isset($answer2)) { echo $answer2; } ?>" />
<br />
<input type="submit" name="validate2" value="Validate my answer" />
<?php
if(isset($erreur2)) {
echo '<font color="red">'.$erreur2."</font>";
}
?>
</TD>
</TR>
</form>
<TR>
<TH> Problem 3 </TH>
<TD> </TD>
<TD> </TD>
<TD> </TD>
<TD> </TD>
<TD>
<form action="" method="POST">
<label for="answer">Your solution :</label>
<input type="text" placeholder="Your answer" id="answer" name="answer" value="<?php if(isset($answer3)) { echo $answer3; } ?>" />
<br />
<input type="submit" name="validate3" value="Validate my answer" />
<?php
if(isset($erreur3)) {
echo '<font color="red">'.$erreur3."</font>";
}
?>
</TD>
</TR>
</form>
</TABLE></p></div>
</div>
</body>
</html> |
Partager