this is the code for my html form:
<!DOCTYPE html>
<head>
<title> Question </title>
<style type = "text/css">
body {
font-family:cursive;
}
a:link {
text-decoration:none;
background-color:#D0D0D0;
color:#000000;
width:100px;
display:block;
text-align:center;
padding:4px;
}
a.visited {
text-decoration:none;
background-color:#D0D0D0;
color:#000000;
width:100px;
display:block;
text-align:center;
padding:4px;
}
a.active {
text-decoration:none;
background-color:#D0D0D0;
color:#000000;
width:100px;
display:block;
text-align:center;
padding:4px;
}
a:hover {
background-color:#686868;
color:#FFFFFF;
}
#title {
text-align:center;
}
</style>
</head>
<body>
<?php
session_start();
?>
<h1 id="title"> Question 1 </h1>
<br/>
<form action="q15.php" method="POST" >
<fieldset>
<legend>Who wrote the music we all recognise from the Paralympics?</legend>
<p>
<input
type="checkbox"
value="your friend"
name="answer"
/>Your Friend
</p>
<p>
<input
type="checkbox"
value="public friend"
name="answer"
/>Public Friend
</p>
<p>
<input
type="checkbox"
value="your enemy"
name="answer"
/>Your Enemy
</p>
<p>
<input
type="checkbox"
value="public enemy"
name="answer"
/>Public Enemy
</p>
<p>
<input
type="submit"
value="Submit"
/>
</p>
</fieldset>
</form>
</body>
</html>
and this is the code for my page which will process the data and update a database which has empty spaces left blank to be filled in later (as in now)
<body>
<h1 id="title"> Quiz </h1>
<?php
session_start();
$connection = mysql_connect("mysql15.000webhost.com", "a4987634_quiz", "********")
or die (mysql_error());
mysql_select_db("a4987634_quiz", $connection)
or die (mysql_error());
$fname = $_SESSION['fname'];
$lname = $_SESSION['lname'];
$id = $_SESSION['ID'];
$answer = $_POST['answer'];
$id = mysql_query("SELECT ID FROM users WHERE fname=$fname LIMIT 1");
if(isset($_POST['answer']) &&
$_POST['answer'] == 'public enemy')
{
?>
<h3 id = "correct"> Correct </h3>
<?php
$sqlcorrect = "UPDATE users SET q1 = correct WHERE ID = $ID LIMIT 1";
mysql_query($sqlcorrect);
(mysql_error());
}
else {
?>
<h3 id = "incorrect"> Incorrect </h3>
<?php
$sqlwrong = "UPDATE users SET q1 = 'wrong' WHERE ID = $ID LIMIT 1";
mysql_query($sqlwrong);
(mysql_error());
}
?>
</body>
</html>
I can connect to the database perfectly and it knows when you get the question correct or incorrect but my problem is when you try to update the database it won't do it. Does anyone have any solutions? There is no error message as well. it doesn't make sense!
unless correct is another column name then you need to surround strings with single quotes. And as the comment says, $ID might be $id depending on your intentions. Should be defined either way though
There are several issues with your query:
This should work, when the right
id
is provided: