Selecting a Row then editing the content of two fields
Posted: Fri Mar 27, 2009 3:11 am
hey everyone, I'm trying to select a row out of a mysql database and edit the content of two fields.
What I've tried to do (which doesn't appear to work): made a drop down menu, the user selects a question and then the script selects the answer in the same row, the question is then displayed in one textarea and the answer in the other, the user would then be able to edit and hit update to change the entree in the database. However the textarea where the answer is supposed to be is blank, and nothing happens when I hit update.
here is my php:
Thanks for any help. -cheers
What I've tried to do (which doesn't appear to work): made a drop down menu, the user selects a question and then the script selects the answer in the same row, the question is then displayed in one textarea and the answer in the other, the user would then be able to edit and hit update to change the entree in the database. However the textarea where the answer is supposed to be is blank, and nothing happens when I hit update.
here is my php:
Code: Select all
<?php
session_start();
if(!isset($_SESSION['adminctrl'])){
header('Location: admin.php'); die('<a href="admin.php">Login first!</a>');
}
$access = mysql_connect("***********", "***", "***") or die(mysql_error());
mysql_select_db('Support', $access) or die(mysql_error());
$error = array();
if(isset($_POST['update'])) {
$question_new = ($_POST['update_q']);
$answer_new = ($_POST['update_a']);
$result = @mysql_query("SELECT question FROM `q_a` WHERE question = '$question'");
@mysql_query("UPDATE message SET question='$question_new' AND answer='$answer_new' WHERE question='$question'");
echo"Update was successful.";
}
?>
<form action="editfaq.php" method="post">
<?php
$conn = "SELECT question FROM `q_a`" ;
$result = mysql_query($conn,$access) or die("Error: ". mysql_error(). " with query ". $conn);
while($row=mysql_fetch_assoc($result))
{
$question[] = $row['question'];
}
echo "<select name='question'>\n";
foreach($question as $y){
echo "<option value='$y'>\n" .$y."</option>\n";
}
echo "</select>\n";
?>
<input type="submit" name="submit" value="Update!" />
</form>
<?php
if (isset($_POST['question'])){
$question = ($_POST['question']);
$r = mysql_query("SELECT answer FROM `q_a` WHERE question = '$question'");
$A = mysql_fetch_assoc($r);
$answer = $A['answer'];
echo "<form method='post' action='editfaq.php'>";
echo "<textarea rows='8' name='update_q' cols='30'>" .$question. "</textarea>";
echo "<br/>";
echo "<textarea rows='8' name='update_a' cols='30'>" .$answer. "</textarea>";
echo "<br/>";
echo "<input type='submit' name='submit' value='Update!' />";
echo "</form>";
}
?>