Jump to content

Explain nr 3?


eduard

Recommended Posts

  • Replies 239
  • Created
  • Last Reply
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.
I changed them, but still get an error!<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> <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>
Link to comment
Share on other sites

:)I think something got translated wrong. thescientist was only explaining your next steps.
Sorry, I thought your comment (nerd) was because of his ultimate sentences!
Link to comment
Share on other sites

it is important in these cases to always provide the output with your post. what is it saying now when you submit the form? From what I can see, I don't think there should be any error messages...

Link to comment
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.

Thank you very much! However still an error:Parse error: syntax error, unexpected T_BOOLEAN_AND, expecting ',' or ')' in /Applications/MAMP/htdocs/website/script.php on line 7
Link to comment
Share on other sites

well, look at line 7. what is it? it says it's expecting a ' or a ). so, I'm guessing this is the line in question:

if(isset($_POST['description'] && isset($_POST['price']) && isset($_POST['quantity'])){

looks like you need an extra ) after isset($_POST['description']you know, it doesn't hurt to try and solve these yourself, that was the whole point of enabling error reporting. edit: I know I posted it with the mistake, but you know, it's a pretty simple mistake that's fairly easy to solve.

Link to comment
Share on other sites

well, look at line 7. what is it? it says it's expecting a ' or a ). so, I'm guessing this is the line in question:
if(isset($_POST['description'] && isset($_POST['price']) && isset($_POST['quantity'])){

looks like you need an extra ) after isset($_POST['description']you know, it doesn't hurt to try and solve these yourself, that was the whole point of enabling error reporting. edit: I know I posted it with the mistake, but you know, it's a pretty simple mistake that's fairly easy to solve.

About the ´edit´, I have ??????????????
Link to comment
Share on other sites

I really don´t understand this output:array(3) { ["description"]=> string(1) "x" ["Price"]=> string(1) "1" ["Quantity"]=> string(1) "2" } invalid form submission. field missingI removed all the capital letters and 1 field is missing! Where? In the database?

Link to comment
Share on other sites

again, please post your code when you have problems. for everytime you post:1) include the code (html and php)2) include any error messageswhat you're seeing at the top of the page:

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

is the raw output of $_POST, which is a global array, in this case containing any data passed from the form submission. You should realize this because you should be able to make out the values submitted along with the name of the form elements. This is how we confirm that the form is actually submitting correctly. This is basic debugging 101.The text output is just telling you what we wrote the script to say. There's absolutely nothing happening with the database. You should be able to figure this out, since there's nothing in the script at all indicating any of the database code we've covered. Right now we are still validating the form submission.So, onto why you are getting the error message.I am going to use caps because you are STILL making a mistake that we've already covered. Your form element names still have caps! I know this because I can see it in the output of $_POST

array(3) { ["description"]=> string(1) "x" ["Price"]=> string(1) "1" ["Quantity"]=> string(1) "2" }
Are you using caps in your script!? They HAVE TO MATCH. case and spelling. show us your code and I guarantee that will be the reason. We just went over this and I thought we were doing this in lowercase.... :)edit: right now it's just a generic error message, it could be any or all of them which are "missing", but full on form validation is not in the scope of this thread. If we manage get full end to end functionality from form to database, then we can go back and enhance the validation process.
Link to comment
Share on other sites

again, please post your code when you have problems. for everytime you post:1) include the code (html and php)2) include any error messageswhat you're seeing at the top of the page:
array(3) { ["description"]=> string(1) "x" ["Price"]=> string(1) "1" ["Quantity"]=> string(1) "2" }

is the raw output of $_POST, which is a global array, in this case containing any data passed from the form submission. You should realize this because you should be able to make out the values submitted along with the name of the form elements. This is how we confirm that the form is actually submitting correctly. This is basic debugging 101.The text output is just telling you what we wrote the script to say. There's absolutely nothing happening with the database. You should be able to figure this out, since there's nothing in the script at all indicating any of the database code we've covered. Right now we are still validating the form submission.So, onto why you are getting the error message.I am going to use caps because you are STILL making a mistake that we've already covered. Your form element names still have caps! I know this because I can see it in the output of $_POSTAre you using caps in your script!? They HAVE TO MATCH. case and spelling. show us your code and I guarantee that will be the reason. We just went over this and I thought we were doing this in lowercase.... :)edit: right now it's just a generic error message, it could be any or all of them which are "missing", but full on form validation is not in the scope of this thread. If we manage get full end to end functionality from form to database, then we can go back and enhance the validation process.

In the output ´yes´(csps), but in my form ´NO
Link to comment
Share on other sites

so what's the issue then? you know they need to match in the form and in the script..so just fix it so they match. and post the code when you have problems. please. it makes verifying the problems that much easier, and is just common courtesy when asking people to figure out why your code isn't working.

Link to comment
Share on other sites

In the output ´yes´(csps), but in my form ´NO
The output shows exactly what the form is submitting. The form is submitting names that start with capitals. If you changed the form and saved it, make sure you refresh the page in the browser or you'll still be using the old version.
Link to comment
Share on other sites

I don´t understand this output!array(3) { ["description"]=> string(1) "x" ["Price"]=> string(1) "1" ["Quantity"]=> string(1) "2" } invalid form submission. field missing<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> <html><body><?phpvar_dump($_POST); if(isset($_POST['description']) && isset($_POST['price']) && isset($_POST['quantity'])){ echo 'all fields submitted. do some stuff here';}else{ echo 'invalid form submission. field missing';}; ?></body></html>

Link to comment
Share on other sites

What don't you understand about it? This line:var_dump($_POST);produces this:array(3) { ["description"]=> string(1) "x" ["Price"]=> string(1) "1" ["Quantity"]=> string(1) "2" }Do you understand what that says? It's been explained to you several times, if you don't understand it read the previous few posts where people explain. That is the form data ($_POST).This part:

if(isset($_POST['description']) && isset($_POST['price']) && isset($_POST['quantity'])){echo 'all fields submitted. do some stuff here';}else{echo 'invalid form submission. field missing';}

produces this:invalid form submission. field missingtherefore, the if statement is false, because one or more of the things you're checking for are not set. We've told you several times why they are not set, if you don't understand that read the previous few posts where people explain.

Link to comment
Share on other sites

What don't you understand about it? This line:var_dump($_POST);produces this:array(3) { ["description"]=> string(1) "x" ["Price"]=> string(1) "1" ["Quantity"]=> string(1) "2" }Do you understand what that says? It's been explained to you several times, if you don't understand it read the previous few posts where people explain. That is the form data ($_POST).This part:
if(isset($_POST['description']) && isset($_POST['price']) && isset($_POST['quantity'])){echo 'all fields submitted. do some stuff here';}else{echo 'invalid form submission. field missing';}

produces this:invalid form submission. field missingtherefore, the if statement is false, because one or more of the things you're checking for are not set. We've told you several times why they are not set, if you don't understand that read the previous few posts where people explain.

Thanks!
Link to comment
Share on other sites

What don't you understand about it? This line:var_dump($_POST);produces this:array(3) { ["description"]=> string(1) "x" ["Price"]=> string(1) "1" ["Quantity"]=> string(1) "2" }Do you understand what that says? It's been explained to you several times, if you don't understand it read the previous few posts where people explain. That is the form data ($_POST).This part:
if(isset($_POST['description']) && isset($_POST['price']) && isset($_POST['quantity'])){echo 'all fields submitted. do some stuff here';}else{echo 'invalid form submission. field missing';}

produces this:invalid form submission. field missingtherefore, the if statement is false, because one or more of the things you're checking for are not set. We've told you several times why they are not set, if you don't understand that read the previous few posts where people explain.

This: var_dump($_POST);produces this:array(3) { ["description"]=> string(1) "x" ["Price"]=> string(1) "1" ["Quantity"]=> string(1) "2" }I don´t understand! Neither can I find it in the tutorials!
Link to comment
Share on other sites

var_dump($_POST); is showing you the structure of the $_POST array

array(3) { ["description"]=> string(1) "x" ["Price"]=> string(1) "1" ["Quantity"]=> string(1) "2" }
array(3) -> Represents the type of the $_POST and the number of elements which it holds.["description"]=> string(1) "x" -> ["description"] is the key name of the array member. and x is the value which it contains. string represents the data type of "x" and the number(1) represents the length of the data ("x")same with->["Price"]=> string(1) "1"["Quantity"]=> string(1) "2" more details http://php.net/function.var_dump from the manual.
Link to comment
Share on other sites

So, I can omit ´var_dump´in my script.php and neither do I understand this error: Parse error: syntax error, unexpected T_ELSE in /Applications/MAMP/htdocs/website/script.php on line 8 (T_ELSE)?

Link to comment
Share on other sites

So, I can omit ´var_dump´in my script.php...
Yes. The use of var_dump is for debugging your code. This is typically only ever used when there are problems.
...and neither do I understand this error: Parse error: syntax error, unexpected T_ELSE in /Applications/MAMP/htdocs/website/script.php on line 8 (T_ELSE)?
It means there's an unexpected ELSE on line 8. Exactly what it says. Post your PHP code and show us which one is line 8. From the code you posted before I can't pick out the error, but perhaps you're using a different version.EDIT:Maybe it's the semicolon at the end of the if/else block?if(isset($_POST['description']) && isset($_POST['price']) && isset($_POST['quantity'])){echo 'all fields submitted. do some stuff here';}else{echo 'invalid form submission. field missing';}; <--- Try removing this semicolon
Link to comment
Share on other sites

Yes. The use of var_dump is for debugging your code. This is typically only ever used when there are problems.It means there's an unexpected ELSE on line 8. Exactly what it says. Post your PHP code and show us which one is line 8. From the code you posted before I can't pick out the error, but perhaps you're using a different version.EDIT:Maybe it's the semicolon at the end of the if/else block?if(isset($_POST['description']) && isset($_POST['price']) && isset($_POST['quantity'])){echo 'all fields submitted. do some stuff here';}else{echo 'invalid form submission. field missing';}; <--- Try removing this semicolon
Parse error: syntax error, unexpected T_ELSE in /Applications/MAMP/htdocs/website/script.php on line 7OTHER SCRIPT.PHP:<html><body><?php if(isset($_POST['description']) && isset($_POST['price']) && isset($_POST['quantity']));{ echo "all fields submitted";else echo "invalid form submission" ?></body></html>
Link to comment
Share on other sites

:)Why would you take a perfectly working segment of code and destroy it like that?Working version:if(isset($_POST['description']) && isset($_POST['price']) && isset($_POST['quantity'])){echo 'all fields submitted. do some stuff here';}else{echo 'invalid form submission. field missing';}Your version:if(isset($_POST['description']) && isset($_POST['price']) && isset($_POST['quantity']));{echo "all fields submitted";elseecho "invalid form submission"I'll leave it up to you to spot the differences.

Link to comment
Share on other sites

:)Why would you take a perfectly working segment of code and destroy it like that?Working version:if(isset($_POST['description']) && isset($_POST['price']) && isset($_POST['quantity'])){echo 'all fields submitted. do some stuff here';}else{echo 'invalid form submission. field missing';}Your version:if(isset($_POST['description']) && isset($_POST['price']) && isset($_POST['quantity']));{echo "all fields submitted";elseecho "invalid form submission"I'll leave it up to you to spot the differences.Thanks! Finally, got it: all fields submitted
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.


×
×
  • Create New...