I have made a page in HTML/PHP and I would like a function to be able to edit some files though the web-page. I have a <textarea> tag to do this.
However, I cannot seem to enter any default value to the <textarea> through PHP variables.
Here is my code
<?php
$text = file_get_contents("file.txt");
?>
<textarea name="input">
<?php echo $text; >?
</textarea>
But the text that appears is "<?php echo $text; ?>"
Please help, I couldn't find help anywhere else.
You misplaced your ending PHP tag (>? should be ?>) when echoing the result into the textarea.
<?php
$text = file_get_contents("file.txt");
?>
<textarea name="input">
<?php echo $text; ?>
</textarea>
You should check your php knowledge:
line 5 should be ?> not >?. Then it will be valid.
Related
I have a html form with a textbox in which i want to pull the name of the person signed in to automatically be filled in the text box when the page loads. below is the code i am using.
<input type="text" autocomplete="off" name="createdby" id="createdby" value= <?= $first_name.' '.$last_name ?> readonly>
the issue is with the php code
<?= $first_name.' '.$last_name ?>
Because of the space between .' ' . the last name does not show. however when i remove the space both the first name and the last name show but without any spaces. How do i pull both names from the database and have them separated
I believe it needs to look as follows:
<...value="<?= $first_name.' '.$last_name ?>" readonly>
You should use double quotes around your php tags.
implode() looks better then such concatenation:
implode(' ', array($first_name, $last_name));
Convert this:
<?= $first_name.' '.$last_name ?>
Into this:
<?php echo $first_name.' '.$last_name ?>
Or this if you want to simplify variables concatenation:
<?php echo “$first_name $last_name” ?>
Use the standard php tags and explicitly echo your values
I am currently trying to write a program that outputs the stdout output of a c program to a text area in html (using php).
This is what I have thus far:
<?php
$output = shell_exec("./hello");
?>
<textarea name="view" cols="80" rows="24" readonly>
<?php echo $output; ?>
</textarea>
This prints the correct output, but it adds 2 tabs ahaed of the first character, so instead of
Hello World!
It prints
Hello World!
This is my first time using either php or html, so I'm sure it's something fairly easy to fix. I just can't seem to find anything addressing this specifically online, so any help would be greatly appreciated!
(Just in case it's not obvious the c program is just a simple hello world, that prints fine on the terminal).
Everything that is out of the php tags are echoed "as-is". Consequently, you echoed two tabs in front of your <?php echo $output; ?> within the textarea.
try this :
<textarea name="view" cols="80" rows="24" readonly><?php echo $output; ?></textarea>
This is because of your whitespaces inside the <textarea> tags:
<textarea name="view" cols="80" rows="24" readonly>
<?php echo $output; ?>
</textarea>
The text between your tags will be taken as the textareas value.
So your value will be 4 whitespaces and then the output of your echo statement.
tl;dr: Remove your indent (4 spaces):
<textarea name="view" cols="80" rows="24" readonly>
<?php echo $output; ?>
</textarea>
Here's my code for my simple CRUD site:
<textarea id="bb" class="form-control"name="text" placeholder="Edit this question, <?= $_SESSION['name'] ?>?"> <?= $text ?> </textarea>
But the problem is that the textarea has 2 tab spaces at the beginning of the text and after the text there is a space with a tab space next to it.
I'm very sure that the text is trimmed in the MySQLi database. I'm using Bootstrap BTW.
Thanks in advance.
Remove space between <textarea></textarea>
<textarea id="bb" class="form-control"name="text" placeholder="Edit this question, <?= $_SESSION['name'] ?>?"><?= $text ?></textarea>
I have HTML code for a table in database. I want to present that code in its original form in a textarea so that I can make changes in it. When I echo it appears in compiled form (table), not in original HTML code. How can I display its original HTML code?
<textarea rows="40" cols="30" name="content" id="content">
<?php echo '<pre>'.$row['content'].'</pre>'; ?>
</textarea>
You can use the <code> tag to achieve this.
Try replacing < by <
<?php echo '<pre>'.str_replace('<', '<',$row['content']).'</pre>'; ?>
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.