There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
 
Tag Cloud
access audio avg avg 8 bios blue screen boot bsod computer connection cpu crash css dell desktop driver drivers dvd email error excel explorer firefox firefox 3 freeze gimp graphics hard drive hardware hijackthis hjt install internet internet explorer itunes keyboard laptop macro malware missing monitor network networking outlook outlook 2003 outlook 2007 outlook express password popups problem problems router seo server slow sound sp3 spyware trojan usb video virtumonde virus vista vundo windows windows vista windows xp winxp wireless
Web Design & Development
Search
Search in:
 
Advanced Search
Tech Support Guy Forums > Internet & Networking > Web Design & Development >
Solved: php error - kinda


HELLO AND WELCOME! Before you can post your question, you'll have to register -- it's completely free! Click here to join today! We highly recommend that you print a copy of our Guide for New Members. Enjoy!

 
Thread Tools
knight_47's Avatar
Senior Member with 1,187 posts.
 
Join Date: Mar 2006
Location: →
Experience: Um... Green?!
01-Nov-2006, 06:27 PM #1
Solved: php error - kinda
well the codes at least compiling, but theres a small problem. The only way I can think of to fix is by using form action="phpfile.php" but I'm wondering why this doesn't work.

The link. it's not suppose to show the result unless you hit enter. How can I prevent this?

the code:
PHP Code:
<?php 

$a1 
= ($_POST['a1'] == "a1");
$a2 = ($_POST['b1'] == "b2");
$a3 = ($_POST['c1'] == "c2");
$a4 = ($_POST['d1'] == "d2");
$a5 = ($_POST['e1'] == "e1");  

if (
$_POST['Submit'] AND $a1 AND $a2 AND $a3 AND $a4 AND $a5
{
echo 
"Results: <br />";
echo 
"Congratulations! You got all the answers right! That is a 100%!";
}
else
{
echo 
"Opps! <br />";
echo 
"One or more problems are incorrect, please go back and re-check your answers!";
}

?>
__________________
brendandonhu's Avatar
Distinguished Member with 15,988 posts.
 
Join Date: Jul 2002
Location: Ann Arbor, MI
Experience: Advanced
01-Nov-2006, 08:26 PM #2
What exactly are you trying to do with this?
$a1 = ($_POST['a1'] == "a1");
$a2 = ($_POST['b1'] == "b2");
$a3 = ($_POST['c1'] == "c2");
$a4 = ($_POST['d1'] == "d2");
$a5 = ($_POST['e1'] == "e1");
knight_47's Avatar
Senior Member with 1,187 posts.
 
Join Date: Mar 2006
Location: →
Experience: Um... Green?!
01-Nov-2006, 08:49 PM #3
lol i know it's stupid, but I'm just trying to prefect my variable making. :P
covert215's Avatar
Account Disabled with 2,651 posts.
 
Join Date: Apr 2006
Experience: Web Designer
01-Nov-2006, 09:30 PM #4
Test for NULL. If NULL, echo nothing. Nest the if statements.
brendandonhu's Avatar
Distinguished Member with 15,988 posts.
 
Join Date: Jul 2002
Location: Ann Arbor, MI
Experience: Advanced
01-Nov-2006, 10:00 PM #5
No need to nest the if() that will just make it longer. Just use this for your variables.
$a1 = $_POST['a1'];
$a2 = $_POST['b1'];
$a3 = $_POST['c1'];
$a4 = $_POST['d1'];
$a5 = $_POST['e1'];
knight_47's Avatar
Senior Member with 1,187 posts.
 
Join Date: Mar 2006
Location: →
Experience: Um... Green?!
01-Nov-2006, 11:09 PM #6
What do you mean next the if()?

I fixed the variables, thanks.
namenotfound's Avatar
Computer Specs
Distinguished Member with 2,049 posts.
 
Join Date: Apr 2005
Location: New York
Experience: I know what I know, I am what I am.
01-Nov-2006, 11:21 PM #7
Quote:
Originally Posted by knight_47
What do you mean next the if()?

I fixed the variables, thanks.
nesting would be like this

if (this == that) {
if (here == there) {
echo "something";
}
}

One IF statement nested within another.
knight_47's Avatar
Senior Member with 1,187 posts.
 
Join Date: Mar 2006
Location: →
Experience: Um... Green?!
01-Nov-2006, 11:36 PM #8
Quote:
Originally Posted by namenotfound
nesting would be like this

if (this == that) {
if (here == there) {
echo "something";
}
}

One IF statement nested within another.
But wouldn't that be the same as

if xxxx && xxxxx && xxxxx
{
echo "x";
}
namenotfound's Avatar
Computer Specs
Distinguished Member with 2,049 posts.
 
Join Date: Apr 2005
Location: New York
Experience: I know what I know, I am what I am.
02-Nov-2006, 05:23 AM #9
I guess so. I was just giving an example of what "nesting" is
covert215's Avatar
Account Disabled with 2,651 posts.
 
Join Date: Apr 2006
Experience: Web Designer
02-Nov-2006, 06:40 AM #10
Quote:
Originally Posted by knight_47
But wouldn't that be the same as

if xxxx && xxxxx && xxxxx
{
echo "x";
}
That is NOT the same, when you use IF-ELSE statements. It alters the flow of logic.
knight_47's Avatar
Senior Member with 1,187 posts.
 
Join Date: Mar 2006
Location: →
Experience: Um... Green?!
02-Nov-2006, 08:54 AM #11
So how would I fix the problem?

I'm pretty much a beginner at PHP, and don't know much as of now, so I get easily confused...
brendandonhu's Avatar
Distinguished Member with 15,988 posts.
 
Join Date: Jul 2002
Location: Ann Arbor, MI
Experience: Advanced
02-Nov-2006, 03:16 PM #12
Your code doesn't really make sense because you aren't checking the answers to the quiz anywhere but here's a start
PHP Code:
<?php
$a1 
$_POST['a1'];
$a2 $_POST['b1'];
$a3 $_POST['c1'];
$a4 $_POST['d1'];
$a5 $_POST['e1'];

if(isset(
$_POST['submit']))
{
  if (
$a1 AND $a2 AND $a3 AND $a4 AND $a5)
  {
    echo 
"Results: <br />";
    echo 
"Congratulations! You got all the answers right! That is a 100%!";
  }
  else
  {
    echo 
"Opps! <br />";
    echo 
"One or more problems are incorrect, please go back and re-check your answers!";
  }
}
?>
knight_47's Avatar
Senior Member with 1,187 posts.
 
Join Date: Mar 2006
Location: →
Experience: Um... Green?!
02-Nov-2006, 06:47 PM #13
What do you mean the code doesn't make sense?

If the user hits submit, AND this, AND that, AND this, then echo, Congrats!

If not, echo, something else.

I haven't tried you're code yet, i'm not home yet, but I will in a bit.
brendandonhu's Avatar
Distinguished Member with 15,988 posts.
 
Join Date: Jul 2002
Location: Ann Arbor, MI
Experience: Advanced
02-Nov-2006, 06:52 PM #14
I mean your code is going to tell them they got 100% regardless of what answers they select.
namenotfound's Avatar
Computer Specs
Distinguished Member with 2,049 posts.
 
Join Date: Apr 2005
Location: New York
Experience: I know what I know, I am what I am.
02-Nov-2006, 07:02 PM #15
Knight, why don't you just use the method I posted on the other site?

http://xenweb.net/forums/16333-post10.html

It works, and you wouldn't be pulling your hair out right now trying to get that code to work
If you want I can write it up using your questions and answers
__________________
------------------------
| 404: Name Not Found |
------------------------
PLEASE NOTE: If I happen to help you in a post, or just simply reply to it, doesn't mean I want to be bombarded with PMs. I answer all questions in posts, not in PMs. Thank you, and have a good day.

<?php $h = 'Hello '; $w = 'World'; echo $h.$w; ?>

My Favorite Editors:
Windows: Crimson Editor
Mac: Taco HTML Edit
Linux: gPHPEdit
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are Off
Refbacks are Off

You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 01:27 AM.
Copyright © 1996 - 2008 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Powered by Cermak Technologies, Inc.