Jump to content

Don´t understand this line?


eduard

Recommended Posts

I ddon´t understand this line:if (isset($_POST["price']) && isset($_POST['description']) && isset($_POST['quantity']))isset, (), POST

Link to comment
Share on other sites

I ddon´t understand this line:if (isset($_POST["price']) && isset($_POST['description']) && isset($_POST['quantity']))isset, (), POST
really?ok, I guess we need to go over them again.POST - is a global array in PHP. (like GET). In the context of forms, it is one way to pass data from a form and have it available to a script in PHP. If you had a form with inputs for price, description, and quantity and submitted, $_POST['price'], $_POST['description'], and $_POST['quantity'] is how you would access their values.isset - is a function in PHP for checking if a variable is set, basically that it exists. http://php.net/manual/en/function.isset.phpreturn true if the variable exists, or false if it doesn't, or equals null. In the context of submitting a form, you would want to make sure required form values exist before trying to do something with them (like for an email, or to put into a database). Checking for all three of them in this manner gives you the confidence that you can procede with the rest of what your script needs to do. If any one of these was not present (i.e. not submitted) then one of the return values for isset() would be false, and then everything within the curly braces of the if statement would not execute.() - are parenthesis. Are used to enclose statements for if/else statement, loops, and for grouping mathematical operation when precedence and order is required.edit: fixed my description about parens
Link to comment
Share on other sites

Do you remember those two files we were working with before? form.html and script.php? Do you remember how we went through it all with you to get it to print out the description, price, and quantity on the screen after you clicked the submit button? That is the code you need to be working with. We've told you this numerous times. You need to add the INSERT query to your code in script.php just like scientist showed you in this post:
Look again. The internal parentheses are required for the isset calls.Eduard, check the quotation marks in $_POST["price']
woops, I thought I wrapped up each one of them in their own parens (sometimes I do that..), i.e.
if( (isset($_POST['price'])) && (isset($_POST['quantity'])) && (isset($_POST['description']))){}

edit: edited my post

Link to comment
Share on other sites

really?ok, I guess we need to go over them again.POST - is a global array in PHP. (like GET). In the context of forms, it is one way to pass data from a form and have it available to a script in PHP. If you had a form with inputs for price, description, and quantity and submitted, $_POST['price'], $_POST['description'], and $_POST['quantity'] is how you would access their values.isset - is a function in PHP for checking if a variable is set, basically that it exists. http://php.net/manual/en/function.isset.phpreturn true if the variable exists, or false if it doesn't, or equals null. In the context of submitting a form, you would want to make sure required form values exist before trying to do something with them (like for an email, or to put into a database). Checking for all three of them in this manner gives you the confidence that you can procede with the rest of what your script needs to do. If any one of these was not present (i.e. not submitted) then one of the return values for isset() would be false, and then everything within the curly braces of the if statement would not execute.() - are parenthesis. Are used to enclose statements for if/else statement, loops, and for grouping mathematical operation when precedence and order is required.edit: fixed my description about parens
I´m fed up with this isset function (also it isn´t written in the tutorials)!Can i write an MySQL INSERT with a POST array WITHOUT isset?
Link to comment
Share on other sites

It's dangerous. If a user forgets to enter data in one of those fields, your INSERT may fail.What aren't you getting about isset? The only problem I see is the incorrect quotation marks here: ["price']

Link to comment
Share on other sites

I'd learn it now. There's still much more to learn about server side validation, most notably mysql_real_escape_string. isset is pretty easy. It's just a simple function. I'm not sure what it is you're not getting, as you never really explain the details regarding the sources of your frustration regarding specific issues.

Link to comment
Share on other sites

woops, I thought I wrapped up each one of them in their own parens (sometimes I do that..), i.e.
if( (isset($_POST['price'])) && (isset($_POST['quantity'])) && (isset($_POST['description']))){}

edit: edited my post

The problem is-also I´ve written this before-: it´s very difficult to see: () or {} (but it is a significant difference!)
Link to comment
Share on other sites

well, if you've learned the basics you would already know when they are used and in what contexts. Maybe change your monitor resolution or increase the zoom on your web browser?

Link to comment
Share on other sites

Look again. The internal parentheses are required for the isset calls.Eduard, check the quotation marks in $_POST["price']
Someone wrote me there is no difference between " and (single-I don´t have it on my keyboard!)But, certainly there is!
Link to comment
Share on other sites

there isn't any difference (for the most part), but you aren't using them correctly. they have to be used as matched pairs. if you start with a ", you end with a ". If you start with a ', then you need to end with '.

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...