Jump to content
eduard

Explain nr 3?

Recommended Posts

I wrote many times that I´m just a beginner! Webroot? I don´r know well what it is (I´m sure I can find it at Google) But most of your replies are as I´m experienced and I´m not!I´ll give you an example that is clear for me: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: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: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.So, I don´t agree with you that I forget all the things I´ve learned (some I do!), but also this I have written before, I get confused by many different replies-which mostly mean the same-but are written in a different way!
This is nothing DIFFERENT than any of us have told you. One file is for your form. One file for your script. All in the same folder. The form submits to the script and passes the information. There has been no CONFLICT in these explanations WHATSOEVER. It's straight from the tutorials too. Your problem is that you don't read (we have caught you at least twice in this thread alone).From the beginning we have told you about the webroot. It is the MAMP folder where you need to put all your web documents. This has been explained to you over many, many, many, many weeks of your threads and posts, all starting back to when you asked how to install MAMP.So I will stand by my assessment that you don't retain information well. I will also stand by my assessment that you have a hard time learning. I don't what the problem is, but there's something wrong with this equation of you asking for help, and us helping you. We give you consistent, solid, documented instructions for how to do things, and then you don't follow them.For example, you have a fully working example that you've QUOTED, yet you still have nothing to show for it, because you don't even know where to put the files, and that's something we've explained to you hundreds of times over months. I don't what else to do for you. We can't force the information to stay in your head. So you can't blame us for having to repeat ourselves over and over and over again....

Share this post


Link to post
Share on other sites

SAVE THIS SOMEWHERE FOR REFERENCE. It's been explained a hundred times before, and in this thread as well. If you can't remember anything, you should write it down.Webroot - the folder in which all web documents need to be saved. For MAMP, this is /Applications/MAMP/htdocs. This is equivalent to opening

localhost:

in your web browser. This where ALL your website related files should be located, PHP and HTML, CSS and images. THIS is your website folder.Now, as you've posted and been given, you know that you have two files. form.html and script.php. BOTH of these files need to be in that webroot. Side by side.With MAMP running, and your web browser open, open form.html. Fill out the form and submit it and tell us what happens and exactly what steps you took. When you do come back, include the code for both form.html and script.php.

Share this post


Link to post
Share on other sites
This is nothing DIFFERENT than any of us have told you. One file is for your form. One file for your script. All in the same folder. The form submits to the script and passes the information. There has been no CONFLICT in these explanations WHATSOEVER. It's straight from the tutorials too. Your problem is that you don't read (we have caught you at least twice in this thread alone).From the beginning we have told you about the webroot. It is the MAMP folder where you need to put all your web documents. This has been explained to you over many, many, many, many weeks of your threads and posts, all starting back to when you asked how to install MAMP.So I will stand by my assessment that you don't retain information well. I will also stand by my assessment that you have a hard time learning. I don't what the problem is, but there's something wrong with this equation of you asking for help, and us helping you. We give you consistent, solid, documented instructions for how to do things, and then you don't follow them.For example, you have a fully working example that you've QUOTED, yet you still have nothing to show for it, because you don't even know where to put the files, and that's something we've explained to you hundreds of times over months. I don't what else to do for you. We can't force the information to stay in your head. So you can't blame us for having to repeat ourselves over and over and over again....
This is all true! However no user is the same, like no child is the same! Everyone needs a different aproach!

Share this post


Link to post
Share on other sites
SAVE THIS SOMEWHERE FOR REFERENCE. It's been explained a hundred times before, and in this thread as well. If you can't remember anything, you should write it down.Webroot - the folder in which all web documents need to be saved. For MAMP, this is /Applications/MAMP/htdocs. This is equivalent to opening
localhost:

in your web browser. This where ALL your website related files should be located, PHP and HTML, CSS and images. THIS is your website folder.Now, as you've posted and been given, you know that you have two files. form.html and script.php. BOTH of these files need to be in that webroot. Side by side.With MAMP running, and your web browser open, open form.html. Fill out the form and submit it and tell us what happens and exactly what steps you took. When you do come back, include the code for both form.html and script.php.

Like this! I call it ´aggressive´ teaching (Capitals, italics, short sentences (instructions?) No, this way doesn´t work for me. However, thanks! Edited by eduardchile

Share this post


Link to post
Share on other sites

This is what I did:HTML form:Description: Price: Quantity: (opened with Safari, Decription: x, Price: 1, Quantity: 1 > SUBMITResult:<html><body><?phpif (isset($_POST['description'])) { echo "The description of this product is ".$_POST['description']; } else { echo "Invalid submission"; } if (isset($_POST['price'])) { echo "The price of this product is ".$_POST['price']; } else { echo "Invalid submission"; } if (isset($_POST['quantity'])) { echo "The quantity of this product is ".$_POST['quantity']; } else { echo "Invalid submission"; } ?></body></html>

Edited by eduardchile

Share this post


Link to post
Share on other sites

What does this message mean?array(0) { } invalid submission because of description

Share this post


Link to post
Share on other sites

I finally know what ´the problem´is! I have little time to study, but I have a lot of pressure and therefore a lot of stress (AFTER my website is finished I´ll explain why?)That´s why I have been trying to study fast-which isn´t possible for these studies-and although it´s going better now, I still studying too fast (=not good!)I ask too many questions, get too many replies which I´m not able to read thoroughly in the spare time I have and as I wrote yesterday I get confused bby the many different(?) replies!I intend to study more relaxed and I prefer another time to have replies by 1 person! ShadowMage if it´s ok for him!

Share this post


Link to post
Share on other sites
What does this message mean?array(0) { } invalid submission because of description
Well, I am assuming that the "array(0) { }" stuff is supposed to be your POST array. If it is, it means it's empty. Which means that a submission never happened, or the submission had no data.I'm a little confused though, because the error message doesn't match anything in the code you posted. There is no line in that code that prints "invalid submission because of description". The only thing printed is "Invalid submission" on all three if blocks. When you post code you need to make sure that you post the exact code that you are using. It would also help if you showed us the HTML code for your form.
I prefer another time to have replies by 1 person! ShadowMage if it´s ok for him!
This is an open forum where all members are free to view and post in all topics. You cannot expect a single person to be the only one to help you. You will most likely discourage others from helping you when you ask a question that person doesn't know the answer to. In addition, if only one person is giving you replies and you have an urgent question it may be days before they see it and respond.

Share this post


Link to post
Share on other sites

nor did he include any code that would actually output the array to screen. I'm sure one big part of it is it's just an issue of the form input element names not matching the POST keys in the php script. but who am I to repeat and point out what's already been said, right? The OP is adamant in only learning from one seemingly random person at a time (the last big thread it was boen_robot who pulled the lucky honor) for literally giving the same advice everyone else gives, yet is ironically comfortable taking my posts and advice and starting threads with them to further his knowledge. :)Posting with some caps is not meant to be aggressive, but to emphasize the fundamental basics the you need to know. You need to know what a webroot is. You need to know how HTML and PHP (and databases) interact with each other. A lot of this isn't even technical, but merely theoretical. It's the stuff in a book that's not code. It is the higher level discussion topics that you learn before you code. If you don't plan on learning, then don't plan on having an easy time understanding the code required to write it. If it seems like we're frustrated in teaching you it's because we are. If you are too stressed to learn, then come back when you aren't. You made it clear that not an option, so if you insist on defying rational logic, then prepare for the feedback that will ensue for taking a seemingly simple concept (even for newbies) and drawing them out into endless, fruitless conversations. It's not we're being paid to this or anything. You seem to take this board for granted. That's certainly the longest road possible to achieving your goals.

Edited by thescientist

Share this post


Link to post
Share on other sites
Well, I am assuming that the "array(0) { }" stuff is supposed to be your POST array. If it is, it means it's empty. Which means that a submission never happened, or the submission had no data.I'm a little confused though, because the error message doesn't match anything in the code you posted. There is no line in that code that prints "invalid submission because of description". The only thing printed is "Invalid submission" on all three if blocks. When you post code you need to make sure that you post the exact code that you are using. It would also help if you showed us the HTML code for your form.This is an open forum where all members are free to view and post in all topics. You cannot expect a single person to be the only one to help you. You will most likely discourage others from helping you when you ask a question that person doesn't know the answer to. In addition, if only one person is giving you replies and you have an urgent question it may be days before they see it and respond.
Ok!However, I´ll tell you something of my present situation:Since 1 month now I walk (with a walker!). But because I am also with this a brginner, I need a lot of time for my shopping.So I do shopping 3 times a week (monday, wednesday and friday). The other days (tuesday, thursday, saturday, sunday) I spend studying and doing things which are necessary (cleaning, washing clothes, etc) and because I´m disabled I need a lot of time for this. Therefore, I can´t study (unfornately!) as much as I would, but the pressure is very high! (I´ll explain later!) But I want to finish this as soon as possible, because as you know, I do this to present myself as someone who can create a database! My website will be finished if I have an english and spanish version! Both working perfect!

Share this post


Link to post
Share on other sites
nor did he include any code that would actually output the array to screen. I'm sure one big part of it is it's just an issue of the form input element names not matching the POST keys in the php script. but who am I to repeat and point out what's already been said, right? The OP is adamant in only learning from one seemingly random person at a time (the last big thread it was boen_robot who pulled the lucky honor) for literally giving the same advice everyone else gives, yet is ironically comfortable taking my posts and advice and starting threads with them to further his knowledge. :)Posting with some caps is not meant to be aggressive, but to emphasize the fundamental basics the you need to know. You need to know what a webroot is. You need to know how HTML and PHP (and databases) interact with each other. A lot of this isn't even technical, but merely theoretical. It's the stuff in a book that's not code. It is the higher level discussion topics that you learn before you code. If you don't plan on learning, then don't plan on having an easy time understanding the code required to write it. If it seems like we're frustrated in teaching you it's because we are. If you are too stressed to learn, then come back when you aren't. You made it clear that not an option, so if you insist on defying rational logic, then prepare for the feedback that will ensue for taking a seemingly simple concept (even for newbies) and drawing them out into endless, fruitless conversations. It's not we're being paid to this or anything. You seem to take this board for granted. That's certainly the longest road possible to achieving your goals.
I´ve explained this night how my current situation is! I want to study more relaxed which means better reading and better (less!) questions!

Share this post


Link to post
Share on other sites
Well, I am assuming that the "array(0) { }" stuff is supposed to be your POST array. If it is, it means it's empty. Which means that a submission never happened, or the submission had no data.I'm a little confused though, because the error message doesn't match anything in the code you posted. There is no line in that code that prints "invalid submission because of description". The only thing printed is "Invalid submission" on all three if blocks. When you post code you need to make sure that you post the exact code that you are using. It would also help if you showed us the HTML code for your form.This is an open forum where all members are free to view and post in all topics. You cannot expect a single person to be the only one to help you. You will most likely discourage others from helping you when you ask a question that person doesn't know the answer to. In addition, if only one person is giving you replies and you have an urgent question it may be days before they see it and respond.
HTML form:<html><head><style type="text/css">#desc{width:10%;height:5%;}</style><title>POST</title></head><body><form action='script.php' method="post">Description: <input type="text" name="description" id="description"><br />Price: <input type="text" name="Price" id="Price" /><br />Quantity: <input type="text" name="Quantity" id="quantity" /><input type='submit' value='Submit' /></form></body></html> Present script php:<html><body><?phpvar_dump($_POST);if (isset($_POST['description'])) { echo "The description of this product is ".$_POST['description']; } else { echo 'invalid submission because of description'; } ?></body></html>

Share this post


Link to post
Share on other sites

Ok, if that is the actual code and you have these two files saved in the same folder in your MAMP directory all you should have to do is load form.html in your browser (ie, type http://localhost/form.html) fill out the form and click submit. You should see the array dump and your description message.

Share this post


Link to post
Share on other sites
Ok, if that is the actual code and you have these two files saved in the same folder in your MAMP directory all you should have to do is load form.html in your browser (ie, type http://localhost/form.html) fill out the form and click submit. You should see the array dump and your description message.
I don´t manage (File not found). I have saved the html.form and the script.php in the folder website which is saved in the folder htldocs of MAMP

Share this post


Link to post
Share on other sites

In that case:http://localhost/website/form.htmlYour "htdocs" folder is the same as "http://localhost". To address any file or folder within that folder, you add the path after "htdocs" to "http://localhost", as above.

Share this post


Link to post
Share on other sites
In that case:http://localhost/website/form.htmlYour "htdocs" folder is the same as "http://localhost". To address any file or folder within that folder, you add the path after "htdocs" to "http://localhost", as above.
Thanks! However it doesn´t work! (File not found)

Share this post


Link to post
Share on other sites
I don´t manage (File not found). I have saved the html.form and the script.php in the folder website which is saved in the folder htldocs of MAMP
I hope you saved it as form.html :)What is the exact path to your files?If your files are saved directly in htdocs the path should be localhost/form.htmlIf your files are in a folder named "website" which is in htdocs your path would be localhost/website/form.htmlAs boen_robot pointed out, whatever the path to your files is, you would type the same thing in your browser. Folder/file names need to be exact spelling, possibly even exact case. Try not to use spaces in any file or folder names. They do work, but they require encoding.

Share this post


Link to post
Share on other sites

Is the HTML file called "form.html" or is it something else?What about the port?http://localhost:8888/website/form.html We've been over this before too... how were you able to access the files last time? What address did you typed in your address bar to get the error about invalid submission due to description?

Share this post


Link to post
Share on other sites

Finally, I managed-a file and a folder were named different-but I got this as output:array(3) { ["description"]=> string(1) "x" ["Price"]=> string(1) "1" ["Quantity"]=> string(1) "2" } The description of this product is xInvalid submissionInvalid submission<html><body><?phpvar_dump($_POST);if (isset($_POST['description'])) { echo "The description of this product is ".$_POST['description']; } else { echo 'invalid submission because of description'; } if (isset($_POST['price'])) { echo "The price of this product is ".$_POST['price']; } else { echo "Invalid submission"; } if (isset($_POST['quantity'])) { echo "The quantity of this product is ".$_POST['quantity']; } else { echo "Invalid submission"; } ?></body></html>

Share this post


Link to post
Share on other sites
Finally, I managed-a file and a folder were named different-but I got this as output:array(3) { ["description"]=> string(1) "x" ["Price"]=> string(1) "1" ["Quantity"]=> string(1) "2" } The description of this product is xInvalid submissionInvalid submission
Your names and indexes need to match exactly, case and spelling.In your form you have:Description: <input type="text" name="description" id="description"><br />Price: <input type="text" name="Price" id="Price" /><br />Quantity: <input type="text" name="Quantity" id="quantity" />But in the PHP you have:if (isset($_POST['description']))if (isset($_POST['price']))if (isset($_POST['quantity']))Notice the capitalization of price and quantity. Those need to match.

Share this post


Link to post
Share on other sites

Finally! Now we're getting somewhere...If you look at the var_dump() part:

array(3) { ["description"]=> string(1) "x" ["Price"]=> string(1) "1" ["Quantity"]=> string(1) "2" }

Notice that you have $_POST['description'], $_POST['Price'] and $_POST['Quantity']. You are correctly using

if (isset($_POST['description']))

but then you're using

if (isset($_POST['price']))

and

if (isset($_POST['quantity']))

which is different from what you have... do you see it, or do I need to spell that out too?[edit]Well... ShadowMage said it explicitly... look at his post, right before this one.[/edit]

Share this post


Link to post
Share on other sites
Finally! Now we're getting somewhere...If you look at the var_dump() part:
array(3) { ["description"]=> string(1) "x" ["Price"]=> string(1) "1" ["Quantity"]=> string(1) "2" }

Notice that you have $_POST['description'], $_POST['Price'] and $_POST['Quantity']. You are correctly using

if (isset($_POST['description']))

but then you're using

if (isset($_POST['price']))

and

if (isset($_POST['quantity']))

which is different from what you have... do you see it, or do I need to spell that out too?[edit]Well... ShadowMage said it explicitly... look at his post, right before this one.[/edit]

S**T

Share this post


Link to post
Share on other sites

could of seen that one coming... :)Anyway, it's good to see some forward progress finally being made! :)Well, once you fix those $_POST variable names, you will probably want to consider revising your conditional's to check for all of those members (for numeric arrays their called indexes, for associative arrays their called members/keys) at once. In this way, it will force the script to only do what you want it to do if all three of those items have been submitted. so something like this would be more appropriate:

if(isset($_POST['description']) && isset($_POST['price']) && isset($_POST['quantity'])){  echo 'all fields submitted.  do some stuff here';  //here is where you would want to add code for interacting with the database}else{  echo 'invalid form submission.  field missing';};

since we have already gone over inserting, it's merely integrating those steps we have gone over with you, which is1) making a connection to the database2) selecting the table3) creating and executing the query4) *(optional but recommended): printing out some sort of success/failure message to the screenpretty soon you will completed your first step in being a developer of databases. If you have access to phpMyAdmin, after you make a successful request to the database, you will start seeing your submitted form data appearing in the table, and that will certainly be a good feeling. I know it was the first day I did this. I was actually pretty excited, haha.edit: fixed a syntax error in the conditional statement.

Edited by thescientist

Share this post


Link to post
Share on other sites
...you will start seeing your submitted form data appearing in the table, and that will certainly be a good feeling. I know it was the first day I did this. I was actually pretty excited, haha.
Nerd. :)

Share this post


Link to post
Share on other sites
could of seen that one coming... :)Anyway, it's good to see some forward progress finally being made! :)Well, once you fix those $_POST variable names, you will probably want to consider revising your conditional's to check for all of those members (for numeric arrays their called indexes, for associative arrays their called members/keys) at once. In this way, it will force the script to only do what you want it to do if all three of those items have been submitted. so something like this would be more appropriate:
if(isset($_POST['description'] && isset($_POST['price']) && isset($_POST['quantity'])){  echo 'all fields submitted.  do some stuff here';  //here is where you would want to add code for interacting with the database}else{  echo 'invalid form submission.  field missing';};

since we have already gone over inserting, it's merely integrating those steps we have gone over with you, which is1) making a connection to the database2) selecting the table3) creating and executing the query4) *(optional but recommended): printing out some sort of success/failure message to the screenpretty soon you will completed your first step in being a developer of databases. If you have access to phpMyAdmin, after you make a successful request to the database, you will start seeing your submitted form data appearing in the table, and that will certainly be a good feeling. I know it was the first day I did this. I was actually pretty excited, haha.

Sorry, I prefer women! :)

Share this post


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

×
×
  • Create New...