Login | Register | FAQ
Anonymous

User input and conditions example

+ Post a reply

7 posts Page 1 of 1


User input and conditions example

by sm2012 » Thu Dec 20, 2012 3:42 pm

Hello,

I am having problems with the 'User input and conditions' example. The previous example works fine and the html file links to the php file and displays 'Hello myname', but in the second example, I type my name and choose a colour and the resulting php file is blank, rather than showing a coloured screen and 'Hello myname'.

I have tried copying and pasting the code but it still results in a blank page. I am using Firefox.

Does anybody have any ideas?

Thanks.
User avatar

sm2012

  • Posts: 5
  • Joined: Thu Dec 20, 2012 3:29 pm

Re: User input and conditions example

by XainPro » Fri Dec 21, 2012 10:15 am

you can try this example online maybe there is some filname mistake in your code etc
here is the example in online mode
http://html.net/tutorials/php/lesson11_ex2.php
is your script file name i s
handler.php ?
User avatar

XainPro

  • Posts: 3933
  • Joined: Fri Feb 17, 2012 8:10 pm

Re: User input and conditions example

by sm2012 » Fri Dec 21, 2012 2:07 pm

Thanks. The example works fine, it just doesn't work when I try to run the code as I type or copy it (There may be one mistake in the code, shouldn't there be a : after 'case "g"' rather than a ; ? I tried both anyway). The other examples 'Contact form' and 'Requesting form data with PHP' work fine, so I've no idea.
User avatar

sm2012

  • Posts: 5
  • Joined: Thu Dec 20, 2012 3:29 pm

Re: User input and conditions example

by XainPro » Sat Dec 22, 2012 7:40 pm

well there is no a
Code: Select all
<?php

   $strHeading = "<h1>Hello " . $_POST["username"] . "</h1>";

   switch ($_POST["favoritecolor"]) {
   case "r":
      $strBackgroundColor = "rgb(255,0,0)";
      break;
   case "g";
      $strBackgroundColor = "rgb(0,255,0)";
      break;
   case "b":
      $strBackgroundColor = "rgb(0,0,255)";
      break;
   default:
      $strBackgroundColor = "rgb(255,255,255)";
      break;
   }

   ?>

   <html>
   <head>
   <title>Form</title>

   </head>
   <body style="background: <? echo $strBackgroundColor; ?>;">

   <? echo $strHeading; ?>

   </body>
   </html>
User avatar

XainPro

  • Posts: 3933
  • Joined: Fri Feb 17, 2012 8:10 pm

Re: User input and conditions example

by sm2012 » Sat Dec 22, 2012 8:34 pm

I meant shouldn't it be 'case"g":' not 'case"g";' ?

It doesn't make an difference to the result of running the code on my machine anyway.
User avatar

sm2012

  • Posts: 5
  • Joined: Thu Dec 20, 2012 3:29 pm

Re: User input and conditions example

by XainPro » Mon Dec 24, 2012 2:05 pm

sm2012 wrote:I meant shouldn't it be 'case"g":' not 'case"g";' ?

It doesn't make an difference to the result of running the code on my machine anyway.


oh yah sorry it should be ( : )
User avatar

XainPro

  • Posts: 3933
  • Joined: Fri Feb 17, 2012 8:10 pm

Re: User input and conditions example

by Hawk147 » Wed Jan 09, 2013 4:52 am

I had the same issue, until I realized that the file name was incorrect. I made the form page as 'form.html', and made the handler page as 'handler.php'. I refreshed the browser, and it worked fine. Make sure you have no typos with the codes....hopes this works...Peace
User avatar

Hawk147

  • Posts: 29
  • Joined: Tue Jan 08, 2013 8:43 am


+ Post a reply

Page 1 of 1

cron