php problems

 
Post new topic   Reply to topic    Aprelium Forum Index -> PHP
View previous topic :: View next topic  
Author Message
john76
-


Joined: 16 Jun 2005
Posts: 22
Location: Middlesbrough

PostPosted: Thu Jul 28, 2005 8:56 pm    Post subject: php problems Reply with quote

having a few problems getting this simple, but annoying code to work...
I've tried numerous changes, read loads of webpages, but to no avail!


part 1....
Code:

<html>
<head>
<title>Form</title>
</head>
<body bgcolor="#000000" text="#FFFFFF">
<form method="post" action="send.php">
<p>Your name: <input type="text" name="name" /></p>
<p>Your age: <input type="text" name="age" /></p>
<p><input type="submit" value="Send" /></p>
</form>
</body>
</html>


then to part 2
Code:

<?php
if($_POST["name"]=="john") || ($_POST["age"]=="21")
      {
   echo"1";
      }
elseif($_POST["name"]=="beck") || ($_POST["age"]=="20")
      {
   echo"2";
      }
else   {
   echo"none"
   }
?>


any help would be good, as i'm just starting out with php and don't want to be put off.
Back to top View user's profile Send private message Visit poster's website MSN Messenger
MonkeyNation
-


Joined: 05 Feb 2005
Posts: 921
Location: Cardiff

PostPosted: Thu Jul 28, 2005 9:05 pm    Post subject: Reply with quote

Code:
<?php
if($_POST["name"]=="john" || $_POST["age"]=="21")
      {
   echo"1";
      }
elseif($_POST["name"]=="beck" || $_POST["age"]=="20")
      {
   echo"2";
      }
else   {
   echo"none";
   }
?>

Your not supposed to close the brackets then put more seperated by |s, you need to put them all inside the same brackets.
And you missed a semicolon on the none =)

EDIT: Wait, are you after the name AND age to be true, youll need to use && instead of ||. || is or, && is and.
_________________
Back to top View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger ICQ Number
john76
-


Joined: 16 Jun 2005
Posts: 22
Location: Middlesbrough

PostPosted: Thu Jul 28, 2005 9:23 pm    Post subject: Many thanks Reply with quote

Cheers for the rapid reply. Changed the code, and it worked, kinda. I wanted both name and age to be correct , so I changed the || to a & and it works how I want it to now. just got to change the echo's to url's and I'll be happy.

john
Back to top View user's profile Send private message Visit poster's website MSN Messenger
cmxflash
-


Joined: 11 Dec 2004
Posts: 872

PostPosted: Thu Jul 28, 2005 9:43 pm    Post subject: Reply with quote

Code:
<?php
if($_POST["name"]=="john" || $_POST["age"]=="21")
      {
header("Location: site1.html");
      }
elseif($_POST["name"]=="beck" || $_POST["age"]=="20")
      {
header("Location: site2.html");
      }
else   {
   echo"Access denied";
   }
?>


There you go...
Back to top View user's profile Send private message
john76
-


Joined: 16 Jun 2005
Posts: 22
Location: Middlesbrough

PostPosted: Thu Jul 28, 2005 9:58 pm    Post subject: thanks again Reply with quote

much tidier than the meta refresh I wrote in lol
Back to top View user's profile Send private message Visit poster's website MSN Messenger
cmxflash
-


Joined: 11 Dec 2004
Posts: 872

PostPosted: Thu Jul 28, 2005 10:33 pm    Post subject: Reply with quote

And faster, i guess
Back to top View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Aprelium Forum Index -> PHP All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB phpBB Group