473,503 Members | 2,352 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Php script is producing an error "undefined index: question"

16 New Member
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3.  
  4.  /*the points system for this Q&A has to be passed from question to question.  
  5. We are going
  6. to do this by passing it in the URL.  After the first question, the current score is
  7.  passed
  8. through in the URL for the form POST,*/ 
  9.  
  10. $question1="
  11. <b>Question 1: What is the URL to access the PHP users manual online?</b><br>
  12. A) <input type=radio name='q1a' value='a'> http://www.php.org/docs.php<br>
  13.  
  14. B) <input type=radio name='q1a' value='b'> http://www.php.com/docs.php<br>
  15.  
  16. C) <input type=radio name='q1a' value='c'> http://www.php.net/docs.php<br>
  17.  
  18. D) <input type=radio name='q1a' value='d'> http://documentation.php.net<br>
  19.  
  20.  
  21. <input type=submit value='Go'>
  22.  
  23. </form>";
  24. $question1_answer="c";
  25.  
  26.  
  27. $question2="
  28. <b>Question 2: What is the extention that PHP documents generally have?</b><br>
  29.  
  30. A) <input type=radio name='q2a' value='a'> .phps<br>
  31.  
  32. B) <input type=radio name='q2a' value='b'> .html<br>
  33.  
  34. C) <input type=radio name='q2a' value='c'> .htm<br>
  35.  
  36. D) <input type=radio name='q2a' value='d'> .php<br>
  37.  
  38.  
  39. <input type=submit value='Go'>
  40.  
  41.  
  42. </form>";
  43.  
  44. $question2_answer="d";
  45.  
  46.  
  47. //the final bit in here is a review of each question, and the correct answer(s) for that question.
  48.  
  49. $results=$question1."<br><b>Correct answer: $question1_answer</b><br><i>Why: The other domains go somewhere else.</i><br><br>";
  50.  
  51. $results.=$question2."<br><b>Correct answer: $question2_answer</b><br><i>Why: .php is the default extention the server is setup for, 
  52.                                                                          tho any extention can be setup to parse as a PHP script</i><br><br>"; 
  53.  
  54. $results.="Ok, now I understand, take me <a href='hello.php'>back to the beginning</a> to try again.";
  55.  
  56.  
  57.  
  58.  
  59.  
  60. //the code below is where am having a problem am getting an error "undefined index error:question"
  61. switch($_GET['question']) 
  62. {
  63.  
  64.     case "1":
  65.  
  66.                  print "<form method=post action='hello.php?question=2'>$question1
  67.  
  68. </form>";
  69.  
  70. }
  71. ?>
Am a beginner in programming trying to learn php on my own.As i have commented on the last piece of code, the switch statement that is where my problem is am getting an error saying "undefined index:question" and the word "question" is found on my switch condition statement. i think there is a problem in the way i write my form statement inside my switch statement.please help!!
Sep 29 '11 #1
10 2281
Rabbit
12,516 Recognized Expert Moderator MVP
It means that there is no key with the name question being passed in the GET array when the page is being loaded.
Sep 29 '11 #2
fadhili
16 New Member
what does it mean by saying there is no key?
Oct 6 '11 #3
Rabbit
12,516 Recognized Expert Moderator MVP
When the form submitted, there was nothing on there called question.
Oct 6 '11 #4
fadhili
16 New Member
so what was i suppose to do?
Oct 7 '11 #5
Rabbit
12,516 Recognized Expert Moderator MVP
Pass in a field named question from your form.
Oct 7 '11 #6
fadhili
16 New Member
Thank you, but how do i do that if i have already declared my question to be $quetion1 and i want it to be displayed on the screen so that user on answering he should prompt question2 later on .Please sorry coz my problem is that am just a beginner in programing.
Oct 7 '11 #7
Rabbit
12,516 Recognized Expert Moderator MVP
But that's the thing. I don't see any indication that you've declared the question to be question 1. You've defined a variable to hold question 1 but no where in the code does it say that the default question is question 1. Nor have you indicated that you've passed in question 1 in the first place. In the absensce of this, I have to assume that there is no question parameter passed in.
Oct 7 '11 #8
fadhili
16 New Member
okay thank you for hint, but can you help maybe by a code example to elaborate to me what you mean by no question parameters passed in plz!
Oct 10 '11 #9
Rabbit
12,516 Recognized Expert Moderator MVP
If the URL I use is www.mysite.com/index.php?question=1
then this won't give an error $_GET['question'].

However, if the URL I use is www.mysite.com/index.php
then this will give me the error you're getting $_GET['question'].

In the first example, I passed in the 'question' variable through GET. In the second example, there is no 'question' variable, so the PHP code errors out.
Oct 10 '11 #10
fadhili
16 New Member
hey rabbit thank you very much for the explanation i have understood the concept and corrected it.Passing variables by post method i have been trying to use this but never really understood it well, thank you again.Hopefully you will still support me for my up coming question.
Oct 11 '11 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

2
5605
by: NotGiven | last post by:
I have display error ON and error reporting to E_ALL. I have a form that opens fine. When you submit it, all the fields that have nothing in them, for example an un-selected radio button, throw...
3
7750
by: Steven T. Hatton | last post by:
Scroll to the bottom and read the last part first. I've been trying very diligently to 'modularize' the code from TC++PL3E found here: http://www.research.att.com/~bs/matrix.c I keep getting...
15
4448
by: bill | last post by:
I am trying to write clean code but keep having trouble deciding when to quote an array index and when not to. sometimes when I quote an array index inside of double quotes I get an error about...
4
1688
by: steve | last post by:
Hi, I am trying to compile a sample program using gcc. The program requires headers so I put the header files and corresponding source files into one folder. Then I ran the command 'gcc prog.c -o...
5
7347
by: Pseudonyme | last post by:
Dear All : Ever had an httpd error_log bigger than the httpd access log ? We are using Linux-Apache-Fedora-Httpd 2006 configuration. The PHP lines code that lead too tons of errors are : ...
1
2737
by: grbgooglefan | last post by:
I am importing cStringIO module in my PythonC++ embedded program. The import is failing with the following error: ImportError: /usr/lib/python2.3/lib-dynload/cStringIO.so: undefined symbol:...
1
2118
by: ashjas | last post by:
Hello, i am trying to compile a code(main.cpp) which uses a function that is declared in a header file that is within the directory where the main.cpp file resides so the header is included as ...
4
7679
by: mariaz | last post by:
Hello, I am getting a Notice error on my website that says: Notice: Undefined index: _created_formatted in C:\EasyPHP1-8\www\eP\components\com_jambook\jxtemplate.php(125) : regexp code on line 1 ...
0
2009
by: Nick S | last post by:
Hi I've found very little about this problem and was wondering if someone could help me. I've installed the Apache 2.0.63 and PHP 5.2.6 from the source code on my SuSe Linux 9.3 box. ...
10
29424
by: arvindkuk | last post by:
how to work with expection handing in which when i am using try block then the error message coming that "undefined symbol try" why it is so, please solve my problem.
0
7093
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7291
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7468
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5598
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5023
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4690
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3180
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3171
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1522
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.