Page 1 of 1
Newbie help needed $_get
Posted: Mon Dec 20, 2010 1:33 pm
by iurirosa
Hi,
First off all sorry if my inglish spelling is not that great ! Second im also realy sorry if my questions are simply stupid !
Im new to php programing but im realy interested in learning php and mysql, and i realy apreciate all the help from the persons that take some time to help me out, and teach me php.
I have bean reading the php manual on php.net but there are just some things i dont understand, and when i look at the examples i see realy complex examples of people with some experience, so now im trying to learn some basics of php on this forum.
im trying to play around with some simple code
<form method="GET"> name <input type="text" name="name"/></form>
<?php
$value ="$_GET[name]";
echo "$value";
?>
From what i understand is that the var $value will get the informacion writen in to the form, so than i echo the var $ value so it will print on the screen.
But there is somthing im doeing wrong becouse nothng happens

, can some one please help me by telling me what im doing wrong, and wy is this not working, whats the correct code and wy.
Thank you very mutch.
Re: Newbie help needed $_get
Posted: Mon Dec 20, 2010 1:40 pm
by Jonah Bron
Quotes are for creating strings.
Code: Select all
<?php
$value = $_GET['name'];
echo $value;
?>
You can use either single-quotes ('), or double-quotes ("). Notice that I put name into quotes; that's because it's a string. Read this page of the manual.
http://php.net/language.types.string
Re: Newbie help needed $_get
Posted: Mon Dec 20, 2010 2:03 pm
by Celauran
iurirosa wrote:
im trying to play around with some simple code
Code: Select all
<form method="GET"> name <input type="text" name="name"/></form>
I might be barking up the wrong tree here, but I don't see a submit button. $_GET won't contain any values until the form has been submitted.
Re: Newbie help needed $_get
Posted: Mon Dec 20, 2010 3:59 pm
by iurirosa
Many many thanks to Celauran and Johan Bron.
How ever, As a reply to Johan Bron, when i use either single-quotes ('), or double-quotes (")
I get a parse error
Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' in C:\Programas\Abyss Web Server\htdocs\test.php on line 7
I think the trick was a submit buttom, the code like this worked
Code: Select all
<form method="get">Name <input type="text" name="name" />
<input type="submit">
</form>
<?php
$value="$_GET[name]";
echo $value;
?>
So now im happy i got this code to work.
Re: Newbie help needed $_get
Posted: Mon Dec 20, 2010 4:06 pm
by Jonah Bron
No, get the quotes off. Use this:
Re: Newbie help needed $_get
Posted: Mon Dec 20, 2010 4:44 pm
by iurirosa
Yes, Thank you, it works.
But now im a little confused ???
wy did it work on both ways ??? whats the difference between
Code: Select all
<form method="get">Name <input type="text" name="name" />
<input type="submit">
</form>
<?php
$value = $_GET['name'];
echo $value;
?>
and
Code: Select all
<form method="get">Name <input type="text" name="name" />
<input type="submit">
</form>
<?php
$value="$_GET[name]";
echo $value;
?>
I´m realy interested in this, wy do both ways work ?
Re: Newbie help needed $_get
Posted: Mon Dec 20, 2010 5:02 pm
by Jonah Bron
Read the link I gave to the manual and everything should come clear. That will teach you the basics of strings.
http://php.net/language.types.string
Re: Newbie help needed $_get
Posted: Mon Dec 20, 2010 5:42 pm
by iurirosa
Well i dont realy get it,
A string is a series of characters right ? so
But
$_GET[], is a predefined variabel, wy is 'name' ( in this case) considered a string ?
This is how i see it, it is probably wrong, i just want to know what.
The way of sending the information to the php script was in this case with the method="GET", so this method will pass the information throu your browser.
Now the php script captures the information becouse of the variable $value.
This variable will get the information becouse of the predefined variable $_get, witch has the "information" to capture inside the form the "value", "
name". So i just cant understand wy "name" inside the $_get[] is considered a string ???
I apreciate your help and time, i just want to learn wy php behaves this way if there are any good articles about the logic of php please i also would like to read them. And many thanks for your help !
Re: Newbie help needed $_get
Posted: Mon Dec 20, 2010 6:23 pm
by Jonah Bron
Any text that isn't a special word/special character/variable/function/class is a string. The 'name' string is how PHP looks up the correct value from the array. Almost anything can be used as an index:
resources,
integers,
strings,
booleans,
floats ...
You can read up more about arrays here:
http://php.net/language.types.array
Re: Newbie help needed $_get
Posted: Tue Dec 21, 2010 5:33 am
by iurirosa
Thank you very mutch, that explains allot !!!
hehe i even managed to make a little more complex code, its somthing like ( you only get a welcome message if the name and lastname are the same that are on the php code), next step would be compare with a database, a real log in form.
I know this is probably stupid but if you know some good exercises please tell me ill do my best to make them.
Code: Select all
<form method="get">
Name:<input type="text" name="name" />
Last name:<input type="text" name="lname" />
Submit:<input type="submit" value="submit">
</form>
<?php
$name=$_GET['name'];
$lname=$_GET['lname'];
if ( $name==iuri || $lname==rosa) {
echo " Welcome iurirosa";
} else {
echo " no acess";
}
?>
Re: Newbie help needed $_get
Posted: Tue Dec 21, 2010 1:12 pm
by Jonah Bron
iurirosa wrote:Code: Select all
if ( $name==iuri || $lname==rosa) {
Oops, iuri and rosa are strings.
Code: Select all
if ( $name == 'iuri' || $lname == 'rosa') {
As for exercises, I recommend the w3schools PHP tutorial. A great tutorial for getting your basics down.
http://w3schools.com/php/
Re: Newbie help needed $_get
Posted: Tue Dec 21, 2010 6:40 pm
by iurirosa
OOO yes hehe you are right they are not special words/special character/variable/function/class.
I will have to practice this allot more so next time i wont forget , Thank you for the information.
I will go take a look ate w3schools, and i hope ill learn allot more.
Im realy getting into this, it is realy interesting, sometimes i have to read thing more than once becouse its a bit difficult. I have the feeling the most important in php is getting to learn the way it behaves and the logics of the language, rather than all the predifined functions.
Once again thanks, Iuri Rosa
