How to echo $row["Text'] to a TextField - php

Using PHP I am able to query MySQL database and see the results echo using:
echo $row['Text'];
I would like the information to load into TextField myAnswer instead. Can anyone help?
Thanks

Like this
<input type="text" name="myAnswer" value="<?php echo htmlspecialchars($row['Text']) ?>" />
or
<textarea name="myAnswer" rows="6" cols="40"><?php echo htmlspecialchars($row['Text']) ?></textarea>

None of this seems to work for me. Upon looking further, I found the following:
http://www.daniweb.com/forums/thread252486.html -- You can not manipulate text fields like java or C# or as3 but you can echo or print out html tags and text. if you echo your text you will need to space or manipulate using css and html.
So I guess I can't get the results back from the query in a textbox using PHP and MySQL.
Thanks anyways

Going on assumption from your question, you might try something like:
<input type="textbox" value="<?php echo $row['Text']; ?>" />
If you're thinking about a textarea control it'd be like this:
<textarea><?php echo $row['Text']; ?></textarea>

<input type="text" name="myAnswer" value="<?php echo $row['Text']; ?>" />

<?php if ($row['Text']) {?>
<textarea><?php echo htmlspecialchars($row['Text']); ?></textarea>
<?php } ?>
if you are displaying in the same page, otherwise you can just leave out the if .. check.

Related

PHP - How to pass variable in a text filed with double quote

My query extract a data value from mysql table where are a double quote in the text.
Select mytitle from title_table
The result is: This is my title: "for school"
This value I want to put inside a text field, but is truncated in this position This is my title:
I print the title by this: <?php echo $rows['mytitle']; ?>
How to put the entire title in a text field?
Thanks
Print inside the value of the text field, example:
<input type="text" name="title" value="<?php echo $rows['mytitle']; ?>">
I have resolve this problem. Are easy, but in a first time make a wrong Google search.
I have resolve by this: htmlentities
I think you search for this
<?php
echo '<input type="text" value="' . $rows['mytitle'] . '">';
?>
or in plain HTML with
<input type="text" value="<?=$rows['mytitle'];?>">
Look to, for the second example you must have enabled short_tags in your php.ini or use
<input type="text" value="<?php echo $rows['mytitle'];?>">
try this
<input type="text" name="yourkey" value="<?php echo $rows['mytitle'] ?>" />

Can I echo php value into form?

Is it possible to echo php value into form label? Currently I can only echo into textbox which is editable for the user but I want it to be unable to edit like label, any way I can do so?
Below is for textbox which is able to work
<input style="color:#000000" type="text" value="<?php echo $account['Username']; ?>" name="name" required/>
I tried to echo in label but nothing shown in my web
<label for="fullname"><?php echo $account['Fullname']; ?></label>
Use the echo statement. Like this:
<label><?php echo ("this is a label");?></label>
Of course it is possible.
You can use the echo function like you used it before.
Make sure:
you are using PHP file (*.php)
index in array is not empty
you are using < ? php tags
Try this:
// index.php
<?php
$text = "privet";
?>
<label for="fullname"><?php echo $text; ?></label>
// output is <label for="fullname">privet</label>
read this http://php.net/manual/en/function.echo.php
be careful and read also this http://php.net/manual/en/function.htmlspecialchars.php
BTW: if it still does not working... just use dump to get the variable info
<label><?php echo $var; ?></label> // does not working
// ok -> then dump the var!
<?php var_dump($var); ?> // hmm.. lets see (maybe null or string(0)?) :-)

PHP function only calling one parameter and I need it to call a bunch

Hi there I have a simple form that I am trying to validate using PHP. My problem is that my function that I have created only calls in one field instead of multiple fields.
The form can be seen below
<form method="post" action="cms-nlcreate-process.php" id="formcreatenew" enctype="multipart/form-data">
<fieldset>
<legend>General</legend>
<label>Issue no:</label>
<?php echo valuerequired('svissueno') ?>
<input type="text" name="txtissueno" autofocus value="<?php echo valuereturn('svissueno'); ?>" >
<label>Issue date:</label>
<?php echo valuerequired($_SESSION['svdate']) ?>
<input type="date" name="txtdate">
<label>Introduction</label>
<?php echo valuerequired($_SESSION['svintro']) ?>
<textarea name="txtintro" ><?php echo valuereturn('svintro'); ?></textarea>
<script>toolbar("txtintro");</script>
</fieldset>
<fieldset>
<legend>Academic Messages</legend>
<label>Message from academic head Cape Town</label>
<?php echo valuerequired($_SESSION['svacheadcpt']) ?>
<textarea type="text" name="txtacheadcpt" ><?php echo valuereturn('svacheadcpt'); ?></textarea>
<script>toolbar("txtacheadcpt");</script>
<label>Message from academic head Johannesburg</label>
<?php echo valuerequired($_SESSION['svacheadjhb']) ?>
<textarea type="text" name="txtacheadjhb" ><?php echo valuereturn('svacheadjhb'); ?></textarea>
<script>toolbar("txtacheadjhb");</script>
</fieldset>
And the function can be seen below
function valuerequired($vsessionkey){
if(isset($_SESSION[$vsessionkey]) && $_SESSION[$vsessionkey] == 'na') {
echo '<div class="warning_msg">Value Required</div>'; }
}
The problem is that if I input no data into 'vissueno' my warning div displays but this is not the case on any of the others.
I am new to PHP, would I need to use a for each? I am slightly confused as to where to go from here to fix this.
I have tried using jquery(succesful) but want to learn the PHP way
<?php echo valuerequired($_SESSION['svintro']) ?>
are you sure that there is no mistake? Maybe
<?php echo valuerequired('svintro') ?>
at other places the same
P.S. you do something strange cause you try to echo function result. But function didn't return any value - it make echo itself
Vasiliy Vanchuk Answer is correct. You need to pass the name of the $_SESSION variable you want to check.

Auto Filled textbox in php

I am a beginner.
I created a simple generator of pictures and I would like that when he was generate code in the text box and not as plain text.
Please help.
So it should look like: http://i.stack.imgur.com/cXT7X.jpg
I suppose you are doing something like
echo $code;
to show your code; if this is the case so you only have to do it like this :
echo '<input type="text" name="my_code" value="' . $code . '">';
or
echo '<textarea name="my_code">' . $code . '</textarea>';
That's it
Use basic HTML FORM elements with readonly attribute.
<textarea readonly><?php echo $code; ?></textarea>
Just keep in mind that PHP generates HTML that the browser parses...
<input type="text" name="url" value="<?php echo htmlspeciachars($url,ENT_QUOTES); ?>">
its important to use ENT_QUOTES or some other kind of data filter to avoid XSS.
I didn't understand what i am saying but if you want to set the text inside the text input than you should use value element in input tag. For example your code should look like this :-
<input type="text" value="<?php echo $yourvalue;?>" />
Hope this works for you.

how remove <td>..</td> when echo-ing value inside text input?

I encountered a very strange issue, that I never seen before. I have a loop and I echo the loop's output without any problems using or other similar tags:
<p></php echo $values[1];?></p>
it works like a charm, but when I try to echo the same value inside a text input strange things start to happen. The output inside an input is wrapped in tags.
<input type="text" value="<?php echo $values[1]; ?>"/>
gives me in result (that's how it looks like in web inspector in Chrome):
<input type="text" value=" <td>2.62</td>">
What did I do wrong??
Based on your comments then replace:
<input type="text" value="<?php echo $values[1]; ?>"/>
.. with:
<input type="text" value="<?php echo trim(strip_tags($values[1])); ?>"/>
It really sounds like a mistake that there can be HTML tags inside your variables and if this should not happen then of course this should be fixed
$values[1] contains the data
<td>2.62</td>
If your example is from your actual code, take notice that your first variable is $values[0] and the input one is $values[1]

Categories