Inserting line breaks in mysql from a form [duplicate] - php

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Preserve Line Breaks From TextArea When Writing To MySQL
I have created a form that is inserting data into mysql database but I would like the form to insert line breaks (when I press the return key) into the database from the form so I can have paragraphs when displaying the information from the database. At the moment information from the database is just displaying as all in one line despite pressing the return button on the form (text area) when entering the info.how can I do this? I am using php and am quet new so please help.

You need a <textarea> div , then you will be able to capture the new lines, from there you can just get the input you need via normal $_GET or $_POST
What i am guessing is that you just echo the output from the database, use <pre></pre> for formatting your output or nl2br function of php.

Related

Can't pre-populate textarea fields [duplicate]

This question already has answers here:
Setting value of a HTML form textarea?
(3 answers)
Closed 7 years ago.
I have a form that lets a user submit things like "header" and "description_1". I take this information an build a simple one page website for them. There's a link that lets them edit the page, which reads the fields back from the database and pre-populates the form with it. The form is pre-populated by setting the value attribute of the fields to the data pulled back from the database. This works fine for input fields (485-490 below) but it doesn't work for textarea fields (493-498 below). I've verified that $description_1 does have the right text but setting the textarea value to this text doesn't get it to show up when the form is displayed. Does anyone know what the problem might be? Thanks.
You are close, text areas are a bit different than input fields. While you set the value of an input, you populate a text area by echoing text between the opening and closing the text area tags.
<textarea><?php ehco $foo; ?></textarea>
Text areas work differently than other input fields. Default values are set by adding your text in between the HTML tags.
<textarea><? echo $description_1 ?></textarea>
It's been a while since I 've done this but I think you're going to run into some trickiness with carriage returns. To do that you need to convert the values with nl2br. I think it's like this:
<textarea><? echo nl2br($description_1) ?></textarea>

How to get the data from input without attribute name? [duplicate]

This question already has answers here:
Does form data still transfer if the input tag has no name?
(3 answers)
Closed 9 years ago.
I read $_POST is empty after form submission topic and I wondered how to get the data from input without attribute name?
<input type="text" >
var_dump($_REQUEST)//empty
var_dump(file_get_contents('php://input')) //empty
Basically, the form should be specified its name. If not, you cannot get it from the server-side.
However, the form without name is also valid in HTML5. The reason is that you might sometimes want to use for form submission via AJAX or Javascript app. In many cases

Is it possible to use $_POST from an anchor? [duplicate]

This question already has answers here:
How do you force a web browser to use POST when getting a url?
(11 answers)
Closed 8 years ago.
I'm working on a retail type website and I have the search bar so that when you search for something it shows up in a grid with all the results. Now, all the product names are going to be links that all lead to the same page (result.php) which is full of variables which are filled with the information of the product that was clicked. How would I go about doing something similar to
$name = $_POST['productname'];
but with an anchor tag instead of a text input so I can use it to pull the MySQL data to fill in the page. Is something like this possible?
Click
if(isset($_GET['variablename'])) {
echo $_GET['variablename'];
}
if you use query string in anchor tag you cannot use $_POST.

Prevent HTML file field from being delete after PHP validation roundtrip [duplicate]

This question already has answers here:
Can you re-populate file inputs after failed form submission with PHP or JavaScript?
(2 answers)
Closed 10 years ago.
I have a HTML file field <input name="File" id="FileName" type="file"/>. When I submit the form, I do receive the file, all fine. However, when I validate the user's input and cannot accept the values provided, I will need another round trip. As usual, I will redisplay the form plus error messages.
For text field or textarea I can set the (already) provided value, e.g. by value or just echo the value in the textarea. How could I do the same for file fields? I want to avoid that the user always has to reselect the file in the browser.
-- added --
Comments below are right - there are workarounds described in the mentioned SO questions:
PHP remember file field contents
Can you re-populate file inputs after failed form submission with PHP or JavaScript?
Restoring the value of a input type=file after failed validation
This is not possible - you have to store the file on the server to do this. Then you can show the user a short info about the already stored file and the option to upload a new file or delete the file

how to submit a form from a php script [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Auto Submitting a form (cURL)
I have a form which submits to a php script. In this form I need to collect all the $_POST data and then post this on to another form (the reason for this isn't really relevant but there is a good reason).
My question is once I've collected all the data from the initial form submit, sanitised it and assigned it all to variables how do i then package it all up to send to the next form? The second form is expecting a $_POST with hidden fields with particular name attributes....so how do i do this? do I build the actual html and submit that somehow to the second form or do I buld some sort of array and send that?
hope this makes sense. Kind of hard to put in to words.
You can generate form and submit onLoad by Javascript
You can use curl to send POST query (from your server but not from client)
The better way woudl be to store the sanitized variables in the session.
Collect all the information you need from all the forms you need.
Then after you have all the data needed, then finally update the DB (or Somethign else)
if I understood you well when you open the form you tell it wich acction will it perform
.when you click submit it will take you to the other form.in the other form you can access the values of the input fields from the previous form with $_POST['name_of_the_input_field'].i hope this will help you :D

Categories