Reputation: 1
I'm learning to program and I have come along this tutorial:
http://www.w3resource.com/ajax/working-with-PHP-and-MySQL.php
there is one thing that is unclear to me. In this example there is a assignment:
var data = "book_name=" + book;
data is sent to php file and it is retrieved with statment
$book_name = $_POST['book_name'];
Does =
sign in assignment means some kind of reference here? So in php we retrieve book_name
which in turns refers to book string object?
Am i getting this or am i shooting at fence?
Thans for any answer
Upvotes: 0
Views: 50
Reputation: 8885
the =
sign is a assignment operator
it gives to the operand on the left the value of the operand on the right. nothing more, nothing less.
In your example, you data
variable is probably passed to a post request, resolving in it containing the book, but as mentionned on your question, they could be named differently and it would make no difference.
Upvotes: 0
Reputation: 96
It's the same as you retrieve POST fields. In the "send" method you should pass the arguments in a form "arg=value". For instance, if you want to send two fields you should do:
xhr.send("arg1=value1&arg2=value2")
when retrieve like that
$_POST["arg1"] it will return "value1" $_POST["arg2"] it will return "value2"
For further information read this article!
Upvotes: 1
Reputation: 1450
The = sign in the assignment here is just a way of linking the attribute to the value...so let's say book was "Robinson Crusoe"
you'd pass "book_name=Robinson Crusoe" via POST , and when you retrieve it with $book_name = $POST['book_name']; , book name becomes "Robinson Crusoe". Does this help at all?
Upvotes: 1