nootkan Posted August 8, 2014 Share Posted August 8, 2014 Larry trying to get the pursue exercise for sending multiple values to a script but seem to be not achieving it. Tried all sorts of combinations but keep getting errors. Here is my two scripts: <div><p>Click al link to say hello:</p> <ul> <li><a href="hello.php? first_name=Michael&last_name=Smith">Michael Smith</a></li> <li><a href="hello.php? name=Celia">Celia</a></li> <li><a href="hello.php? name=Jude&Law">Jude</a></li> <li><a href="hello.php? name=Sophia">Sophia</a></li> </ul> </div> <?php // Script 3.7 - hello.php ini_set ('display_errors', 1); // Let me learn from my mistakes error_reporting (E_ALL | E_STRICT); // Show all possible problems // This page should receive a name value in the url //Say "Hello": $name = $_GET['name']; $first_name = $GET['first_name']; $last_name = $GET['last_name']; print "<p>Hello, <span style=\"font-weight:bold;\">$name $first_name $last_name</span>!</p>"; ?> Also tried this in the php script: <?php // Script 3.7 - hello.php ini_set ('display_errors', 1); // Let me learn from my mistakes error_reporting (E_ALL | E_STRICT); // Show all possible problems // This page should receive a name value in the url //Say "Hello": $name = $_GET['name']; $first_name = $GET['first_name']; $last_name = $GET['last_name']; print "<p>Hello, <span style=\"font-weight:bold;\">$name</span>!</p>"; print "<p>Hello, <span style=\"font-weight:bold;\">$first_name</span>!</p>"; print "<p>Hello, <span style=\"font-weight:bold;\">$last_name</span.!</p>"; ?> In the book on page 71 it states: Tip if you want to use a link to send multiple values to a script, separate the name=value pairs with the ampersand like this: hello.php?first_name=Larry&last_name=Ullman. So that is what I was basing my exercise on. What did I miss? Link to comment Share on other sites More sharing options...
Larry Posted August 8, 2014 Share Posted August 8, 2014 You have a space after "hello.php?" Link to comment Share on other sites More sharing options...
nootkan Posted August 9, 2014 Author Share Posted August 9, 2014 Okay made the change and still not working. Here are the errors: Notice: Undefined index: name in /home/mysite/public_html/webdev/phpclass/hello.php on line 17Notice: Undefined variable: GET in /home/mysite/public_html/webdev/phpclass/hello.php on line 18Notice: Undefined variable: GET in /home/mysite/public_html/webdev/phpclass/hello.php on line 19 Hello, ! When look at those lines I can't see anything wrong based on the books explanations. I know I am not understanding something just cannot put my finger on it. Will keep trying though. The errors are telling me that get variable isn't assigned a value right? I thought that $name = $_GET['name']; $first_name = $_GET['first_name']; and $last_name = $_GET['last_name']; were doing that, correct? I see that the $name variable is working fine just not my $first_name or $last_name variables. I also noticed that when I used the second example I get hello Micheal! and Hello ! so obviously the variables should all be inside one print statement instead of their own print statements to look like Hello Michael Smith! For the life of me I cannot get the first and last name variables to work right. I wonder if it may be a setting on my server? Okay what I figured out is that I cannot have the $name variable with the $first_name and $last_name variables in the same php script. It works if I do this: <ul><li><a href="hello.php?first_name=Michael&last_name=Smith">Michael Smith</a></li><li><a href="hello.php?first_name=Celia&last_name=Ayers">Celia Ayers</a></li><li><a href="hello.php?first_name=Jude&last_name=Law">Jude Law</a></li><li><a href="hello.php?first_name=Sophia&last_name=Loren">Sophia Loren</a></li></ul> <?php // Script 3.7 - hello.phpini_set ('display_errors', 1);// Let me learn from my mistakeserror_reporting (E_ALL | E_STRICT);// Show all possible problems// This page should receive a name value in the url//Say "Hello":$first_name = $_GET['first_name'];$last_name = $_GET['last_name'];print "<p>Hello, <span style=\"font-weight:bold;\">$first_name $last_name</span>!</p>";?> But it won't work with a mixture of only first names and both first and last names. Is this right? If so, why? Link to comment Share on other sites More sharing options...
Larry Posted August 17, 2014 Share Posted August 17, 2014 No, that's not right. You'll need to learn to heed and trust your error messages, rather than try to outthink it (this is common when just beginning, and I was certainly guilty of it, too). Here, two of your error messages are "Undefined variable: GET". $_GET is definitely a variable in PHP and it's always existent (I believe). So you probably misspelled it, perhaps missing the underscore. Link to comment Share on other sites More sharing options...
Recommended Posts