0

I have a form where I am getting values from previous page in $GET. I want to fetch around 3 different values from database and display them in textbox. How will I do it? Following is my code for getting data from database.

<?php
require_once('config.php');
$id = $_GET['id'];
$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
if(!$link) {
        die('Failed to connect to server: ' . mysql_error());
}

//Select database
$db = mysql_select_db(DB_DATABASE);
if(!$db) {
        die("Unable to select database");
}
$query = "select question,price,sequence from questions where status = 1 and qid =".$id;
//echo $query;
$result=mysql_query($query);
if (!$result) {
    die('Invalid query: ' . mysql_error());
}
$num_rows = mysql_num_rows($result);
if($num_rows==0) {
 echo '<center><font color="red"><b>No record found!!</b></font></center>';
}
else {
$row = mysql_fetch_array($result);
echo $row['question'];
echo $row['sequence'];
echo $row['price'];
}

?>

Thanks
Pankaj

2
  • textbox as in all the values in a <textarea> or <input type="text" for each value? Commented Jun 2, 2011 at 18:16
  • i want to put each value in different textbox Commented Jun 2, 2011 at 18:26

1 Answer 1

4
<textarea><?php echo htmlentites($row['question']);?></textarea>

or

<input type="text" value="<?php echo htmlentites($row['question']);?>" />

Depending on your fancy.

Sign up to request clarification or add additional context in comments.

3 Comments

but I get values in an array from database. How will I add it to 3 different textboxes. Please check my code which I am using to fetch values from database.
I'm assuming $row['question'] is a string. Right now your code only fetches one record, just fetch two more records?
it is getting 3 values as string $row['question'], $row['sequence'], echo $row['price']

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.