When I allow a user to edit their information, when nothing is changed and another link is hit, the information that was there gets deleted. Why?
Here's what it looks like.
<?php
$con = mysql_connect("myconnection","myusername","mypassword");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("studyquestion", $con);
$subject = $_GET['subject'];
$topic = $_GET['topic'];
$id = $_GET['id'];
$_SESSION['id'] = $id;
echo "<p><i>Questions in $subject/$topic</i></p>";
$result = mysql_query("SELECT * FROM questions WHERE user = '$user' AND subject = '$subject' AND topic = '$topic' AND id = '$id'");
if (!$result) {
echo "You have not added any questions in this topic yet.";
echo $row['question'], "<br>";
echo $row['answer'], "";
echo " - <a href=\"addquestion.php?subject=$subject&topic=$topic\">Add question</a><br><br><br>";
}
else {
echo "<form method='post' action=\"editquestions.php?subject=$subject&topic=$topic\">";
while ($row = mysql_fetch_array($result)) {
$question = $row['question'];
$answer = $row['answer'];
echo "<textarea rows=\"4\" cols=\"50\" wrap=\"physical\" name=\"question\" value='question' class='hintTextbox'>$question</textarea><br />
<textarea rows=\"4\" cols=\"50\" wrap=\"physical\" name=\"answer\" value='answer' class='hintTextbox'>$answer</textarea><br />";
}
echo "<input type='submit' name='submit' value='Update' />
</form>";
}
echo "<table><tr><td>Return to <form name=\"form1\" method=\"post\" action=\"topics.php?subject=$subject\"></td><td>
<input type='submit' name='$subject' value='$subject' /></td></tr></table>";
?>
Here's what it looks like.
<?php
$con = mysql_connect("myconnection","myusername","mypassword");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("studyquestion", $con);
$subject = $_GET['subject'];
$topic = $_GET['topic'];
$id = $_GET['id'];
$_SESSION['id'] = $id;
echo "<p><i>Questions in $subject/$topic</i></p>";
$result = mysql_query("SELECT * FROM questions WHERE user = '$user' AND subject = '$subject' AND topic = '$topic' AND id = '$id'");
if (!$result) {
echo "You have not added any questions in this topic yet.";
echo $row['question'], "<br>";
echo $row['answer'], "";
echo " - <a href=\"addquestion.php?subject=$subject&topic=$topic\">Add question</a><br><br><br>";
}
else {
echo "<form method='post' action=\"editquestions.php?subject=$subject&topic=$topic\">";
while ($row = mysql_fetch_array($result)) {
$question = $row['question'];
$answer = $row['answer'];
echo "<textarea rows=\"4\" cols=\"50\" wrap=\"physical\" name=\"question\" value='question' class='hintTextbox'>$question</textarea><br />
<textarea rows=\"4\" cols=\"50\" wrap=\"physical\" name=\"answer\" value='answer' class='hintTextbox'>$answer</textarea><br />";
}
echo "<input type='submit' name='submit' value='Update' />
</form>";
}
echo "<table><tr><td>Return to <form name=\"form1\" method=\"post\" action=\"topics.php?subject=$subject\"></td><td>
<input type='submit' name='$subject' value='$subject' /></td></tr></table>";
?>