K
K
Kirill2016-02-11 23:01:36
PHP
Kirill, 2016-02-11 23:01:36

Output from db to textarea?

Hello! I need to output from the database to the textarea, what's wrong?

<?php $db = mysql_connect('localhost', 'webrazm1_test', '901kiril');
     if (!$db)
           {
           echo 'Error: Could not connect to database. Please try again later.';
           exit;
           }
     mysql_select_db('webrazm1_test') 
                    or die('Could not select database:'.mysql_error()); 
     $result=mysql_query('SELECT column FROM `main_text`');     
     while($row=mysql_fetch_array($result))

{echo 'Текст<br><textarea name='main_text' id='main_text' cols=37 rows=5>".$row['main_text']."</textarea>';};
 mysql_close($db)
                     or die('Could not close connection'); ?>
doesn't work, what's wrong?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Michael, 2016-02-11
@scherbuk

The visual editor highlighted you.
Syntax error
need something like this:

{echo "Текст<br><textarea name='main_text' id='main_text' cols=37 rows=5>".$row['main_text'].'</textarea>';}

T
ThunderCat, 2016-02-11
@ThunderCat

It is obvious that you have crap with quotes, I would recommend:
firstly, read about quotes in PHP (this also applies to Mikhail);
secondly, instead of constructing

while($row=mysql_fetch_array($result)){
echo 'Текст<br><textarea name='main_text' id='main_text' cols=37 rows=5>".$row['main_text']."</textarea>';};

write
while($row=mysql_fetch_array($result)){ ?>
Текст
<br>
<textarea name='main_text' id='main_text' cols=37 rows=5>
<?=$row['main_text'];?>
</textarea>
<?};?>

It will be both more structured and more understandable (hopefully).
In the comments they unsubscribed that it displays only a white screen - test the output, in the first line enter a simple text output like <? echo "start";?>, if it is displayed, then the request most likely returned an empty value, try to do var_dump() on the variables after the request.
and yes, $result=mysql_query('SELECT column FROM `main_text`'); what is it and where does it choose ???

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question