Jump to content
eduard

Explain nr 3?

Recommended Posts

That means that, for example, $_POST does not have an item called 'description'. If you want to see everything that is in $_POST, you can use print_r:echo '<pre>' . print_r($_POST, true) . '</pre>';That will print the structure of $_POST and show you everything it has in it. If you want to check if those exist to avoid the error, you can do this:$description = isset($_POST['description']) ? $_POST['description'] : '';That is the same as this:
if (isset($_POST['description']))  $description = $_POST['description'];else  $description = '';

Thanks! However, I don´t understand much of it!Which tutorials do I have to be?

Share this post


Link to post
Share on other sites

The PHP form tutorials. If you have specific questions about what you don't understand then ask that also.

Share this post


Link to post
Share on other sites
The PHP form tutorials. If you have specific questions about what you don't understand then ask that also.
´isset´ I´ve never seen, so I don´t know the meaning of it?

Share this post


Link to post
Share on other sites

That checks if a variable is set. The errors were because you were trying to access a variable that was not set, so that is a way to check for it before you access it. The manual page is here:http://www.php.net/manual/en/function.isset.phpIf you want to look up any PHP function, you can type the name into the search box on the top of that page.

Share this post


Link to post
Share on other sites
That checks if a variable is set. The errors were because you were trying to access a variable that was not set, so that is a way to check for it before you access it. The manual page is here:http://www.php.net/manual/en/function.isset.phpIf you want to look up any PHP function, you can type the name into the search box on the top of that page.
Ok, thanks!Have a nice night!´See´ you tomorrow!

Share this post


Link to post
Share on other sites
That checks if a variable is set. The errors were because you were trying to access a variable that was not set, so that is a way to check for it before you access it. The manual page is here:http://www.php.net/manual/en/function.isset.phpIf you want to look up any PHP function, you can type the name into the search box on the top of that page.
Thanks very much!

Share this post


Link to post
Share on other sites

This I don´t understand! (post 25)If you want to check if those exist to avoid the error, you can do this:$description = isset($_POST['description']) ? $_POST['description'] : '';

Share this post


Link to post
Share on other sites
This I don´t understand! (post 25)If you want to check if those exist to avoid the error, you can do this:$description = isset($_POST['description']) ? $_POST['description'] : '';
what about it? He covered isset(), and explained the syntax ( the ? and the : ). You need to be more specific in your questions.edit: in english, you would read it like the if/else statement he gave you. If description is in the POST array, set $description to the value of that key/index ($_POST['description']), else set it to an empty string (""). this makes sure that $description is never undefined and keeps the script form throwing an error prematurely. Edited by thescientist

Share this post


Link to post
Share on other sites
what about it? He covered isset(), and explained the syntax ( the ? and the : ). You need to be more specific in your questions.edit: in english, you would read it like the if/else statement he gave you. If description is in the POST array, set $description to the value of that key/index ($_POST['description']), else set it to an empty string (""). this makes sure that $description is never undefined and keeps the script form throwing an error prematurely.
Thanks!

Share this post


Link to post
Share on other sites

just to supplement however, most developers who write forms typically require certain information to be present before sending the form. So they often check for the existance of those first, and then do their assignments. This makes sure that the form was actually submitted (and it's not just a person landing on the page for the first time in the case of the form and the code being on the same page) and that the required contents are there. So in your case, it would look something like this:

<?phpif( isset($_POST['description']) && isset($_POST['price']) && isset($_POST['quantity']) && isset($_POST['submit'])){  echo 'form submitted and all fields set, process form';  $quantity = $_POST['quantity'];  $description = $_POST['description'];  $price = $_POST['price'];}else{  echo 'invalid form submission';};?>

Share this post


Link to post
Share on other sites

I don´t understand a f?¡¿! of it:<html><body><?phpif(isset($_POST['description']))$description = $_POST['description'];else $description = ''; $price = $_POST['price'];$quantity = $_POST['quantity'];echo "The description" . $description "of a product"?></body></html>Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ',' or ';' in /Applications/MAMP/htdocs/test/post.php on line 16

Share this post


Link to post
Share on other sites

You need another dot after $description in the echo line, and a semicolon at the end of that line.

Share this post


Link to post
Share on other sites

I went back in the tutorials, so how should I continue Adding a _post array?<html><body><?php$txt="description";echo $txt;?></body></html>

Share this post


Link to post
Share on other sites

Do I have to refer to the html form in this php script?

Share this post


Link to post
Share on other sites

I don´t understand the example of the php_POST tutorial It´s html, but where should this code be?

Share this post


Link to post
Share on other sites

what don't you get? A form (written in HTML) submits TO a php script, which anticipates certain keys/indexes to be set in the POST/GET array. You make the form and the HTML work together in tandem based on what you want things to do. Later on you can learn to do it all in one page. But seriously, the concept is not that hard.HTML Page* has a form that submits to a PHP page/script and passes all the form values to the PHP page/scriptPHP script/page* is written to anticipate certain form values from an HTML form and does what you want with them (send an email, update a database, write to screen, whatever)the php script alone will not work (as you expect) until you get the form submitting to it. So in my steps I gave you, that's why the form comes first. A basic test of functionality is to have the php script output POST.

<?phpvar_dump($_POST);?>

If the two are connected correctly, you should see the values as raw data on the screen. From there you can move on to actually doing something with those values.

Edited by thescientist

Share this post


Link to post
Share on other sites

This is all in the tutorials but here goes nothing:Imagine you have two files in the same folder of your web directory. One is an HTML file named form.html and the other is a PHP file named script.phpform.html has the following code:

<html><head><title>POST Example</title></head><body><form action='script.php' method='post'><input type='text' name='fname' /><input type='text' name='lname' /><input type='submit' value='Submit' /></form></body></html>

script.php has the following code:

<?phpif (isset($_POST['fname']) && isset($_POST['lname'])) {   echo "Your name is ".$_POST['fname']." ".$_POST['lname'];} else {   echo "Invalid submission.";}?>

Notice how the form's action attribute has the name of the PHP script in it. And the method attribute has a value of 'post' which means the data will be sent using the POST method and the data will be populated into the $_POST array in the PHP script.Also notice how the inputs' names match the indexes used to access the data in the $_POST array. Whatever name you give to your inputs will be the index you need to use to access its value in the $_POST or $_GET arrays.An HTML form submits to a PHP script. Until a submission has happened, you cannot access any information in the $_POST/$_GET array because it will not exist.

Edited by ShadowMage

Share this post


Link to post
Share on other sites
what don't you get? A form (written in HTML) submits TO a php script, which anticipates certain keys/indexes to be set in the POST/GET array. You make the form and the HTML work together in tandem based on what you want things to do. Later on you can learn to do it all in one page. But seriously, the concept is not that hard.HTML Page* has a form that submits to a PHP page/script and passes all the form values to the PHP page/scriptPHP script/page* is written to anticipate certain form values from an HTML form and does what you want with them (send an email, update a database, write to screen, whatever)the php script alone will not work (as you expect) until you get the form submitting to it. So in my steps I gave you, that's why the form comes first. A basic test of functionality is to have the php script output POST.
<?phpvar_dump($_POST);?>

If the two are connected correctly, you should see the values as raw data on the screen. From there you can move on to actually doing something with those values.

Thanks!

Share this post


Link to post
Share on other sites
This is all in the tutorials but here goes nothing:Imagine you have two files in the same folder of your web directory. One is an HTML file named form.html and the other is a PHP file named script.phpform.html has the following code:
<html><head><title>POST Example</title></head><body><form action='script.php' method='post'><input type='text' name='fname' /><input type='text' name='lname' /><input type='submit' value='Submit' /></form></body></html>

script.php has the following code:

<?phpif (isset($_POST['fname']) && isset($_POST['lname'])) {   echo "Your name is ".$_POST['fname']." ".$_POST['lname'];} else {   echo "Invalid submission.";}?>

Notice how the form's action attribute has the name of the PHP script in it. And the method attribute has a value of 'post' which means the data will be sent using the POST method and the data will be populated into the $_POST array in the PHP script.Also notice how the inputs' names match the indexes used to access the data in the $_POST array. Whatever name you give to your inputs will be the index you need to use to access its value in the $_POST or $_GET arrays.An HTML form submits to a PHP script. Until a submission has happened, you cannot access any information in the $_POST/$_GET array because it will not exist.

Thank you very much!This is clear and exactly what I need to know!

Share this post


Link to post
Share on other sites
This is all in the tutorials but here goes nothing:Imagine you have two files in the same folder of your web directory. One is an HTML file named form.html and the other is a PHP file named script.phpform.html has the following code:
<html><head><title>POST Example</title></head><body><form action='script.php' method='post'><input type='text' name='fname' /><input type='text' name='lname' /><input type='submit' value='Submit' /></form></body></html>

script.php has the following code:

<?phpif (isset($_POST['fname']) && isset($_POST['lname'])) {   echo "Your name is ".$_POST['fname']." ".$_POST['lname'];} else {   echo "Invalid submission.";}?>

Notice how the form's action attribute has the name of the PHP script in it. And the method attribute has a value of 'post' which means the data will be sent using the POST method and the data will be populated into the $_POST array in the PHP script.Also notice how the inputs' names match the indexes used to access the data in the $_POST array. Whatever name you give to your inputs will be the index you need to use to access its value in the $_POST or $_GET arrays.An HTML form submits to a PHP script. Until a submission has happened, you cannot access any information in the $_POST/$_GET array because it will not exist.

form action="script.php" refers to the script.php which in my case contains a POST array?

Share this post


Link to post
Share on other sites
This is all in the tutorials but here goes nothing:Imagine you have two files in the same folder of your web directory. One is an HTML file named form.html and the other is a PHP file named script.phpform.html has the following code:
<html><head><title>POST Example</title></head><body><form action='script.php' method='post'><input type='text' name='fname' /><input type='text' name='lname' /><input type='submit' value='Submit' /></form></body></html>

script.php has the following code:

<?phpif (isset($_POST['fname']) && isset($_POST['lname'])) {   echo "Your name is ".$_POST['fname']." ".$_POST['lname'];} else {   echo "Invalid submission.";}?>

Notice how the form's action attribute has the name of the PHP script in it. And the method attribute has a value of 'post' which means the data will be sent using the POST method and the data will be populated into the $_POST array in the PHP script.Also notice how the inputs' names match the indexes used to access the data in the $_POST array. Whatever name you give to your inputs will be the index you need to use to access its value in the $_POST or $_GET arrays.An HTML form submits to a PHP script. Until a submission has happened, you cannot access any information in the $_POST/$_GET array because it will not exist.

I don´t understand ´here goes nothing´ but your explanation is as I am: simple, clear (?), etc. good for a beginner!

Share this post


Link to post
Share on other sites

Saturday I´ll move to another house so I´ll be some days off-line! Although I don´t have much time what and how can I already put on my website (www.eduardlid.com)-which isn´t finished yet!

Share this post


Link to post
Share on other sites
This is all in the tutorials but here goes nothing:Imagine you have two files in the same folder of your web directory. One is an HTML file named form.html and the other is a PHP file named script.phpform.html has the following code:
<html><head><title>POST Example</title></head><body><form action='script.php' method='post'><input type='text' name='fname' /><input type='text' name='lname' /><input type='submit' value='Submit' /></form></body></html>

script.php has the following code:

<?phpif (isset($_POST['fname']) && isset($_POST['lname'])) {   echo "Your name is ".$_POST['fname']." ".$_POST['lname'];} else {   echo "Invalid submission.";}?>

Notice how the form's action attribute has the name of the PHP script in it. And the method attribute has a value of 'post' which means the data will be sent using the POST method and the data will be populated into the $_POST array in the PHP script.Also notice how the inputs' names match the indexes used to access the data in the $_POST array. Whatever name you give to your inputs will be the index you need to use to access its value in the $_POST or $_GET arrays.An HTML form submits to a PHP script. Until a submission has happened, you cannot access any information in the $_POST/$_GET array because it will not exist.

Is this form nr. 2 (see post 1)?

Share this post


Link to post
Share on other sites

There's only one form, and one PHP script to process it. In reality, you could have one PHP script that can process multiple forms, or have both the form HTML markup and the PHP code to process it in the same file. There are several examples of different ways to process forms here:http://w3schools.invisionzone.com/index.php?showtopic=12509

Share this post


Link to post
Share on other sites
There's only one form, and one PHP script to process it. In reality, you could have one PHP script that can process multiple forms, or have both the form HTML markup and the PHP code to process it in the same file. There are several examples of different ways to process forms here:http://w3schools.invisionzone.com/index.php?showtopic=12509
I understand, but is this nr. 2 to which I refer (post 1)?

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.

×
×
  • Create New...