View previous topic :: View next topic |
Author |
Message |
john76 -
Joined: 16 Jun 2005 Posts: 22 Location: Middlesbrough
|
Posted: Thu Jul 28, 2005 8:56 pm Post subject: php problems |
|
|
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 |
|
 |
MonkeyNation -
Joined: 05 Feb 2005 Posts: 921 Location: Cardiff
|
Posted: Thu Jul 28, 2005 9:05 pm Post subject: |
|
|
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 |
 |
 |
john76 -
Joined: 16 Jun 2005 Posts: 22 Location: Middlesbrough
|
Posted: Thu Jul 28, 2005 9:23 pm Post subject: Many thanks |
|
|
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 |
|
 |
cmxflash -
Joined: 11 Dec 2004 Posts: 872
|
Posted: Thu Jul 28, 2005 9:43 pm Post subject: |
|
|
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 |
|
 |
john76 -
Joined: 16 Jun 2005 Posts: 22 Location: Middlesbrough
|
Posted: Thu Jul 28, 2005 9:58 pm Post subject: thanks again |
|
|
much tidier than the meta refresh I wrote in lol |
|
Back to top |
|
 |
cmxflash -
Joined: 11 Dec 2004 Posts: 872
|
Posted: Thu Jul 28, 2005 10:33 pm Post subject: |
|
|
And faster, i guess  |
|
Back to top |
|
 |
|