Help: Problems with editing submitted form data before publishing.

I have a FAQ script that allows visitors to submit a question via a form.
The site admin can then edit the question, add an answer and publish the content to the FAQ page.

Everything is working fine except for editing the user submitted question. The input form is allowing me to edit the user submitted question and submit a provided answer, though after submission it returns the original user submitted question.

eg: a user submits the question: “wat is capital of england”

the admin can edit the question to: “What is the capital city of the United Kingdom?”
and the answer: “The Capital city of the United Kingdom is London”
Though after editing and submission the edited question isn’t being saved to the database and being save as the original question: “wat is capital of england”

here’s the code from the editfaq.php page where you can edit user submitted questions or existing question and answers:
if (isset($_GET[type]) and $_GET[type] == n) {
$get_new = mysql_query(“SELECT * FROM ofaq_new WHERE id = $_GET[id]”);

while ($row = mysql_fetch_array($get_new)) {
$q = “$row[question]”;
$email = “$row[email]”;
$notify = “$row[notify]”;

if (isset($_GET[edit])) {
mysql_query(“INSERT INTO ofaq_qa (q, a) VALUES (’$q’, ‘$_POST[a]’)”);
mysql_query(“DELETE FROM ofaq_new WHERE id = $_GET[id]”);
echo “$lang[publishednew].”;

if ($notify == 1) {
  $message = "$lang[mail1]\n\n$lang[question]: $q\n$lang[answer]: $_POST[a]\n\n$lang[mail2] $config[name] $lang[mail3]\n$config[faqurl]";
  $message = wordwrap($message, 70);
  $subject = "$lang[yourq] $config[name]";
  $headers = "From: $config[name] <$config[adminmail]>";

  mail($email, $subject, $message, $headers);

} elseif (isset($_GET[id])) {
echo “edit user submitted question


echo "<form action=faqedit.php?type=n&edit=1&id=$_GET[id] method=post>";
echo "$lang[question]:<br />";
echo "<input type=text name=q size=50 value='$q' /><br />";
echo "$lang[answer]:<br />";
echo "<textarea name=a rows=4 cols=50></textarea><br />";
echo "<input type=submit value='$lang[pubnew]' />";
echo "</form>";

} else {
$get_qa = mysql_query(“SELECT * FROM ofaq_qa WHERE id = $_GET[id]”);

if (isset($_GET[id])) {
while ($row = mysql_fetch_array($get_qa)) {
$q = “$row[q]”;
$a = “$row[a]”;

echo "<b>edit existing question</b><p />"; 
echo "<form action=faqedit.php?edit=1&sid=$_GET[id] method=post>"; 
echo "$lang[question]:<br />"; 
echo "<input type=text name=q size=30 value='$q' /><br />"; 
echo "$lang[answer]:<br />"; 
echo "<textarea name=a rows=4 cols=30>$a</textarea><br />"; 
echo "<input type=submit value='$lang[editqa]' />"; 
echo "</form>"; 

} elseif (isset($_GET[edit])) {
mysql_query(“UPDATE ofaq_qa set q=’$_POST[q]’, a=’$_POST[a]’ where id=$_GET[sid]”);
echo “$lang[written]”;
} else {
echo “Oops… Something went horribly wrong!”;

Any help would be really appreciated.

No matter, I fixed it myself. ::slight_smile:

Sponsor our Newsletter | Privacy Policy | Terms of Service