Jump to content

how to put a field pulled from db into txt area


deansaddigh

Recommended Posts

Hi, i have this code

//Get the id
		$id = $_GET["id"];

		$query = "SELECT * FROM faq WHERE faq_id =$id";
				$result = mysql_query($query, $conn) 
					or die('Error, query failed');		
		while($row= mysql_fetch_array($result))
			{	
		echo '<strong>Question:</strong> <p class="important2">'.$row['question'].'</p>';
				echo '<strong>Answer:</strong> <p class="important2">'.$row['answer'].'</p>';
				echo '<hr/> ';
			}

 

Basically i want to be able to modify the question and answer in a form and then update the record, how can i do this?

 

Thanks in advance

If I'm reading the question right, you want to be able to edit what is returned from the DB and update those same DB fields with the data entered in the form fields, correct?

If so, to populate the text areas use

 

echo '<input type="hidden" name="record_id" value="' . $row['record_id'] . '" />'
echo '<textarea name="question" rows="3" cols="40">' . $row['question'] . '</textarea>';

 

Then when the form is submitted (check for submission with an isset() ), sanitize the input and run the UPDATE query, setting the fields to the new values WHERE the db_record_id = submitted_record_id.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.