it's a update form and i want when pressing edit, the input text to be changed with the text in mysql database but it doesn't work.
is there some kind of error which i don't see? or is there alternative way to do this form?
update.php
<?php
include("contentdb.php");
if(isset($_POST['submit'])){
$id= $_GET['id'];
$question=mysql_query("SELECT question FROM quiz");
$opt1=mysql_query("SELECT opt1 FROM quiz");
$opt2=mysql_query("SELECT opt2 FROM quiz");
$opt3=mysql_query("SELECT opt3 FROM quiz");
$answer=mysql_query("SELECT answer FROM quiz");
$sql = "UPDATE $table SET question='$question',opt1='$opt1',opt2='$opt2',opt3='$opt3',answer='$answer' WHERE id='$id'";
$result = mysql_query($sql);
if(mysql_query($sql)) {
echo "<br><br>The quiz has been succesfully updated.<br><br>\n";
}
else{
echo "error";
}
}
?>
<form method="post" action="update.php">
<input type="hidden" name="id" value="<?php echo $id ?>">
<b>Question:</b><br>
<input type="Text" name="question" value="<?php echo $question ?>" size="50">
<br>
<b>Option 1:</b><br>
<input type="Text" name="opt1" value="<?php echo $opt1 ?>" size="30">
<br>
<b>Option 2:</b><br>
<input type="Text" name="opt2" value="<?php echo $opt2 ?>" size="30">
<br>
<b>Option 3:</b><br>
<input type="Text" name="opt3" value="<?php echo $opt3 ?>" size="30">
<br>
<b>Answer</b> (must be identical to correct option):<br>
<input type="Text" name="answer" value="<?php echo $answer ?>" size="30">
<br>
<br>
<input type="submit" name="update" value="Update information">
</form>
contentdb.php
<?php
include("config.php");
$db = mysql_connect("$hostname", "$user","$pass") or die(mysql_error());
mysql_select_db("$database",$db);
?>
config.php
<?php
$database = "database";
$user = "user";
$pass = "pass";
$hostname = "localhost";
$table = "table";
?>
editquizlist.php (the file with edit link)
<HTML>
<link rel="stylesheet" href="quiz.css" type="text/css">
<body><center>
<P> </P>
<B>Admin area - edit the quiz</B>
<br><br>
<table width="300" border="0" cellspacing="0" cellpadding="0">
<?php
include("contentdb.php");
$result = mysql_query("SELECT id, question FROM $table ORDER BY id",$db);
echo "<table>";
while ($row = mysql_fetch_array($result))
{
$id = $row["id"];
$question = $row["question"];
if ($alternate == "1") {
$color = "#ffffff";
$alternate = "2";
}
else {
$color = "#efefef";
$alternate = "1";
}
echo "<tr bgcolor=$color><td>$id:</td><td>$question</td><td>[ <a href='update.php?id=$id'>edit</a> ]</td><td>[ <a href='deletequiz.php?id=$id' onClick=\"return confirm('Are you sure?')\">delete</a> ]</td></tr>";
}
echo "</table>";
?>
<br>
<br>
<a href="editquiz.php">Add a new question to the quiz</a></td>
</tr>
</table>
<br>
<br>
<a href="quizinfo.php">See the full quiz table</a>
</center>
</body>
</HTML>