|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
||||
|
||||
|
Nested if statements causing parse error
Hi I am trying to use phpfreaks "Creating a Membership System" which should be familiar to us as the tutorial is posted somewhere in DevShed however, with a few missing links to example of db.php and the complete download at the end. Saying that it is complete on the phpfreaks.com and that's where I'm refering to. My question is, in the register.php there is a block of code which checks for blanks in the input form by having what look like quite a logical group of if statements;
PHP Code:
It comes up with: parse error, unexpected T_ECHO on the line where it reads:- echo 'You did not submit the following required information! <br />'; I know it's someting to do with nesting an 'if' within the bunch of 'if's but why did millions of people have no trouble and I do? I have a feeling I might have to use a 'while' statement, but how I don't know. Is it my version of php on my hosting site(1&1) which is 4.3.8? |
|
#2
|
|||
|
|||
|
What are all those asterisks?
|
|
#3
|
||||
|
||||
|
The've been put in by the php tags! this is the first time I have used the tags for code, because sometimes you see empty spaces where the code should be and it's quite frustrating to see:-
..........and the your code should be! PHP Code:
However, if you click on the quick reply link the code comes up! Anyway, here is the code if((!$first_name) || (!$last_name) || (!$email_address) || (!$username)){ echo 'You did not submit the following required information! <br />'; if(!$first_name){ echo "First Name is a required field. Please enter it below.<br />"; } if(!$last_name){ echo "Last Name is a required field. Please enter it below.<br />"; } if(!$email_address){ echo "Email Address is a required field. Please enter it below.<br />"; } if(!$username){ echo "Desired Username is a required field. Please enter it below.<br />"; } include 'join_form.html'; // Show the form again! /* End the error checking and if everything is ok, we'll move on to creating the user account */ exit(); // if the error checking has failed, we'll exit the script! } hope that come out alright! |
|
#4
|
|||
|
|||
|
Post a few lines of the code just before your if statements; there may be something there.
|
|
#5
|
||||
|
||||
|
Hi
just before the checking process is: /* Let's strip some slashes in case the user entered any escaped characters. */ $first_name = stripslashes($first_name); $last_name = stripslashes($last_name); $email_address = stripslashes($email_address); $username = stripslashes($username); $info = stripslashes($info); I know that it all works if you have just the first if statement if((!$first_name) || (!$last_name) || (!$email_address) || (!$username)) { echo ("You did not submit the following required information! <br />"); } but when you include the other if statements in between you get the error. |
|
#6
|
|||
|
|||
|
I'm not seeing anything that should be giving you an echo error, but I did notice you posted the if code slightly differently in your later post. Please post the code exactly as you have it -- give me about ten lines on either side of the if routine. Go ahead and put it in PHP tags, even if it does add the asterisks, and I'll take another crack at it. There's some sort of syntax thing going on -- it's just hitting the right line.
|
|
#7
|
||||
|
||||
|
The tutorial is on this link:- http://www.phpfreaks.com/tutorials/40/3.php
This is the surrounding code:- PHP Code:
So the syntax is correct for the 'if' statements? because this works and does not produce any error PHP Code:
|
|
#8
|
|||
|
|||
|
Whatever it is, I'm not seeing it. I don't have PHP handily available right now, either -- I'll run some tests on it when I can.
|
|
#9
|
||||
|
||||
|
I suggest putting or die() on the end of your mysql_query() functions.
Maybe you're database is returning an error. |
|
#10
|
|||
|
|||
|
I tried your script locally, and it's working fine. What data are you putting into the form for these tests?
|
|
#11
|
||||
|
||||
|
Hi Madpawn!
I think I've found the major contribution to the problem. If you recall, you asked about those asterisks, well they must have been picked up when I cut and pasted from the webpage. In Dreamweaver, they show as spaces so they went undetected. Deleting any spaces on the left hand side mopped up most of those unexpected T-Variable errors. However, there are a few things that it falls over for. One is : PHP Code:
change this to : PHP Code:
it's happy! Also, I get parse error, unexpected '}' in the last line for this bit. PHP Code:
And lastly it fall over because of :function makeRandomPassword() { PHP Code:
Can you see those †'s, that's what making it fall over and I can only view them if paste the offending code into this message box and then delete them in Dreamweaver. I'm really sorry guys, I think you have been stratching your heads abit with this one! I really didn't expect this. |
|
#12
|
|||
|
|||
|
That's pretty weird. I'm far from a dreamweaver expert (I basically just use it as a plain editor, but I've never run into that. There must be something you have set, perhaps having to do with indention or tabs, that's causing that. I did notice you have one of those t' after your exit() call -- that's probably what's causing your other parse error.
As for the mysql_error() causing trouble -- that's got me totally stumped. There's no reason that shouldn't work. What error does it give you, exactly? |