By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,751 Members | 1,175 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,751 IT Pros & Developers. It's quick & easy.

form validation

P: 6
Hi all,
I want to learn about server side form validation.I have the following source code. But i dont know the meaning of $_SERVER['PHP_SELF']. When i ran this code it shows an error. The error says multiple choice.

Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
  2. "http://www.w3.org/TR/html4/loose.dtd">
  3. <html>
  4.  <head>
  5.   <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  6.   <title>New HTML Document</title>
  7.  </head>
  8.  <body>
  9.  <?php
  10.    if(isset($_POST['posted'])){
  11.      if($_POST['q1']=="answer1" && $_POST['q2']=="answer2")
  12.       echo  "Right" ;
  13.      else echo "Wrong";
  14.    }
  15.  
  16.    ?>
  17.   <form  method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
  18.   <input type="hidden" name="posted" value="true">
  19.   What is the answer of first question?
  20.   <br>
  21.   <input type="radio" name="q1" value="answer1">Answer1
  22.   <br> 
  23.   <br>
  24.   <input type="radio" name="q1" value="answer2">Answer2
  25.   <br>
  26.   <br>
  27.   <input type="radio" name="q1" value="answer3">Answer3
  28.   <br>
  29.   <br>
  30.   <input type="radio" name="q1" value="answer4">Answer4
  31.   <br>
  32.   <br>
  33.   What  is the answer of second question?
  34.   <br>
  35.   <input type="radio" name="q2" value="answer1">Answer1
  36.   <br> 
  37.   <br>
  38.   <input type="radio" name="q2" value="answer2">Answer2
  39.   <br>
  40.   <br>
  41.   <input type="radio" name="q2" value="answer3">Answer3
  42.   <br>
  43.   <br>
  44.   <input type="radio" name="q2" value="answer4">Answer4
  45.   <input type="submit" value="   submit  " >
  46.  
  47.   </form>
  48.  
  49.  </body>
  50. </html>
Aug 19 '08 #1
Share this Question
Share on Google+
5 Replies


Markus
Expert 5K+
P: 6,050
Please use code tags when posting code in the forums - read the posting guidelines to find out about codee tags.

the error says what now? Please give the full error - we're not psychics.
Aug 19 '08 #2

pbmods
Expert 5K+
P: 5,821
rubelpasha, you were asked by a moderator on July 9 to start using CODE tags:

[CODE=php]
PHP code goes here.
[/CODE]

This message serves as your official warning. Continued violation of the site Posting Guidelines will result in account suspension.

If you have any questions or concerns, feel free to contact me anytime.

Thanks for your time.

pbmods
Aug 19 '08 #3

nathj
Expert 100+
P: 938
Did you try a Google search on $_SERVER['PHP_SELF']?

Check out this article

As for the error if you want help with that specifically then I suggest you post the error message.

I have now spent a few minutes running your code and discovered one problem.
You have:
[PHP]
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">

change to
[PHP]
<form method="post" action=<?php echo '"' .$_SERVER['PHP_SELF'] . '"'; ?>>

[/PHP]

This then does what it is supposed to.
Cheers
nathj
Aug 20 '08 #4

Atli
Expert 5K+
P: 5,058
This then does what it is supposed to.
No actually, that wouldn't change a thing.

The server doesn't know, or care, what all the other stuff in the page is, it only looks for
<?php ?> tags and execute that as PHP code, whether that is inside quotes or not.
Aug 20 '08 #5

Atli
Expert 5K+
P: 5,058
Hi all,
I want to learn about server side form validation.I have the following source code. But i dont know the meaning of $_SERVER['PHP_SELF']. When i ran this code it shows an error. The error says multiple choice.
I tried your code on my test server. I worked perfectly fine.

Did you post the right code?
Aug 20 '08 #6

Post your reply

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