LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 02-20-2003, 07:58 AM   #1
dai
Member
 
Registered: May 2002
Location: Wales
Distribution: Slack 8.1, Gentoo 1.3a, Red Hat 7.3, Red Hat 7.2, Manrake 8.2
Posts: 328

Rep: Reputation: 30
PHP Post and GET method


Hi all

Im starting to learn PHP. Im using the Beginning PHP 4 book by WROX and a couple of SAMS books.

Anyway in one book it explains the process of getting data from a form using the post/get approach by setting Action = "php script"

Thie php script is meant to output on screen the inputted data from the html form and looks like this: -

<?php
echo "thank you $nameofperson"
?>

WHen this script runs (using get method) I can see that the name is passed at the end of the url but the output in the browser is: -

thank you


Has the book Im using got its code wrong??? I have looked at another book and got the code working using $_GET(nameofperson) but I was wondering if its possible to set a script up as shown above???
 
Old 02-21-2003, 02:51 PM   #2
DaveG
Member
 
Registered: Nov 2001
Location: London, UK
Distribution: Fedora 16
Posts: 160

Rep: Reputation: 41
The HTML form needs to have a text input box named "nameofperson" and PHP "track_vars" and "register_globals" must be enabled in the PHP configuration file.
"track_vars" sets up arrays of $HTTP_GET_VARS etc. while "register_globals" makes all form fields avaiable as global variables with the same name as the form field.
Set up a page with just:
<?php phpinfo(); ?>
in it (named phpinfo.php) to see exactly what PHP thinks it's doing.
 
Old 02-21-2003, 05:15 PM   #3
dai
Member
 
Registered: May 2002
Location: Wales
Distribution: Slack 8.1, Gentoo 1.3a, Red Hat 7.3, Red Hat 7.2, Manrake 8.2
Posts: 328

Original Poster
Rep: Reputation: 30
cheers mate I thought it was a prob with setting Global_vars to off (using php 4.2.3 and its set to of by default)

Anybody able to answer this one

When using Switch (case statements) on inputs from another php page why when I use case (and no break) does the default not work. Heres the code for the input form: -


<?php
$Message1="Bugs Bunny";
$Message2="Homer Simpson";
$Message3="Ren & Stimpy";

echo "<Form method=GET action='answer.php'><BR>";
echo "<Strong>Which of the following is the best?</Strong><BR><BR>";
echo "<Input name ='Question' type=radio Value='$Message1'>$Message1<BR>";
echo "<Input name ='Question' type=radio Value='$Message2'>$Message2<BR>";
echo "<Input name ='Question' type=radio Value='$Message3'>$Message3<BR><BR>";
echo "<Input type=submit><Input type=reset>";
echo "</Form>";
?>

And the code for validation


<?php

switch ($_GET[Question])// uses the html name set in the form on page question.php

{//start parentheses for switch statement

case $_GET[Question]=="Bugs Bunny": //colon used for case
echo ("You thinks $_GET[Question] is the best<BR>");//semi-colon used for actions
echo ("Incorrect<BR><BR>");
echo ("<a href = whyu>Click here to try again</a>");
break;

case $_GET[Question]=="Homer Simpson":
echo ("You thinkz $_GET[Question] is the best<BR>");
echo ("Correct $_GET[Question] is the best<BR><BR>");
echo ("<a href = fytf</a>");
break;

case $_GET[Question]=="Ren & Stimpy":
echo ("You thinky $_GET[Question] is the best<BR>");
echo ("Incorrect<BR><BR>");
echo ("<a href = yfuyl]>Click here to try again</a>");
break;

case $_GET[Question]=="":

default:
echo ("You must choose an option");
break;

}//end parentheses for switch statement
?>

Last edited by dai; 02-21-2003 at 05:23 PM.
 
Old 02-26-2003, 01:31 AM   #4
Zorglub
LQ Newbie
 
Registered: Feb 2003
Location: Spain
Distribution: Suse 7.0
Posts: 1

Rep: Reputation: 0
Wink

Hello:

He problem appears to be that it is ommited an html form to show how the variables are passed to php.

I think that you have to put a form in the end of your code (this is html code):

PHP Code:
<form name="test" method="post" action="my_page.php"
PHP Code:
<input type="text" name="nameofperson" value="your name here"
PHP Code:
<input type="submit"
[PHP]</form>

and it will appear a form in your page. If you fill a name -i.e. "dai" in the text box and press the "submit" buttom, the next time the page will show "thank you dai"
 
Old 02-26-2003, 09:45 AM   #5
dai
Member
 
Registered: May 2002
Location: Wales
Distribution: Slack 8.1, Gentoo 1.3a, Red Hat 7.3, Red Hat 7.2, Manrake 8.2
Posts: 328

Original Poster
Rep: Reputation: 30
Thanks for response but the form and GET method work fine.

The problem I get is with the lines

case $_GET[Question]=="":

default:
echo ("You must choose an option");
break;

If I dont select an option then it passes nothing but the output of default does not occur.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Method Not Allowed: The requested method POST is not allowed for the URL /writedhcp.p WiWa Linux - Networking 15 01-06-2011 01:20 PM
wget/curl problems. redirection after post method tommmmmm Linux - Software 1 08-10-2005 10:36 AM
PHP auth method Davus Programming 4 07-31-2005 04:06 PM
looking for http debugger (with get/post method) tommmmmm Linux - Software 0 10-31-2004 09:33 AM
Better method for a php search engine? Pcghost Programming 4 02-18-2004 12:44 PM


All times are GMT -5. The time now is 08:50 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration