SitePoint Sponsor |
|
User Tag List
Results 1 to 13 of 13
Thread: Unexpected T_ELSE
-
May 13, 2003, 14:19 #1
Unexpected T_ELSE
I was reading through one of Kevin Yanks articles (the one about managing users), and I was fiddeling around with some of the code, and I got the following error:
Parse error: parse error, unexpected T_ELSE in /home/virtual/site11/fst/var/www/html/practice/xdesigns/register.php on line 92
The snippet of code that deals with this is as follows:
PHP Code:else:
dbConnect('star-craftx_com');
//make sure the required fields were filled out
if ($username=="" or $password=="" $email=="") {
error("One or more of the required fields were left blank.\\n".
"Please fill them in and try again.");
}
-
May 13, 2003, 14:27 #2
- Join Date
- Apr 2001
- Location
- Canada
- Posts
- 5,458
- Mentioned
- 1 Post(s)
- Tagged
- 0 Thread(s)
you forgot the or between $password=="" $email==""
It's better to use || instead of or as well.Mike
It's not who I am underneath, but what I do that defines me.
-
May 13, 2003, 14:34 #3
Thanks for the || thing, I'll start using that
But I still get the same error..
PHP Code:else:
dbConnect('star-craftx_com');
//make sure the required fields were filled out
if ($username=="" || $password=="" || $email=="") {
error("One or more of the required fields were left blank.\\n".
"Please fill them in and try again.");
}
-
May 13, 2003, 17:00 #4
- Join Date
- Apr 2001
- Location
- Canada
- Posts
- 5,458
- Mentioned
- 1 Post(s)
- Tagged
- 0 Thread(s)
There is an endif; afterwards, right?
I can't see the error here, perhaps a few more lines above and below?Mike
It's not who I am underneath, but what I do that defines me.
-
May 13, 2003, 17:46 #5
Directly above that code is HTML, so I'll post the stuff above that:
PHP Code:<?php //register.php
include("common.php");
include("db.php");
if (!isset($submit));
//display signup form
?>
===========HTML RIGHT HERE============
<?php
else:
dbConnect('star-craftx_com');
//make sure the required fields were filled out
if ($username=="" || $password=="" || $email=="") {
error("One or more of the required fields were left blank.\\n".
"Please fill them in and try again.");
}
//check to see if user has already submitted same username
//same with email address
$sql = "SELECT COUNT(*) FROM design_users WHERE username = '$username'";
$result = mysql_query($sql);
if (!result) {
error("A database error has occured while processing your ".
"submission. [url=file://\nif]\\nif[/url] this error continues, please <a href="maito:koomann@star-craftx.com">contact me</a>");
}
if (@mysql_result($result,0,0)>0) {
error("A user already exists with your chosen Username.\\n".
"Please use a different username.");
}
//if they already used the same email address
$sql = "SELECT COUNT(*) FROM design_users WHERE email = '$email'";
$result = mysql_query($sql);
if (!result) {
error("A database error has occured while processing your ".
"submission. [url=file://\nif]\\nif[/url] this error continues, please <a href="maito:koomann@star-craftx.com">contact me</a>");
}
if (@mysql_result($result,0,0)>0) {
error("A user already exists with your chosen email address.\\n".
"Please use a different email address.");
}
//Finally, insert the data in to the MySQL database.
$sql = "INSERT INTO design_users SET
username='$username',
password='$password',
email='$email',
aim='$aim',
icq='$aim',
msn='$msn',
date_joined=CURDATE,
age='$age',
interests='$interests',
job='$job',
website='$website',
websiteurl='$websiteurl',
websitedescription='$websitedescription'";
if (!mysql_query($sql))
error("An internal error has occurred in processing your ".
"submission.\\nIf this message continues after you try again, please <a href="mailto:koomann@star-craftx.com">contact me</a>.");
?>
-
May 13, 2003, 17:48 #6
- Join Date
- Apr 2001
- Location
- Canada
- Posts
- 5,458
- Mentioned
- 1 Post(s)
- Tagged
- 0 Thread(s)
if (!isset($submit));
//display signup form
should be
if (!isset($submit)) {
//display signup form
and change
else:
dbConnect('star-craftx_com');
//make sure the required fields were filled out
to
} else {
dbConnect('star-craftx_com');
//make sure the required fields were filled out
}
Mike
It's not who I am underneath, but what I do that defines me.
-
May 13, 2003, 18:02 #7
I came to almost the same answer after fiddeling around with it a little bit
But when I run the page, I get the message box error saying that I didn't fill out the form. For some reason, right when you go to the page, it submits it, even when you haven't click anything....
www.star-craftx.com/pracitce/xdesigns/register.php
-
May 13, 2003, 18:07 #8
Nevermind, it's almost working fine now.
But if you take a look at the HTML forms, I only want it so that only the first 3 fields NEED to be filled out, the rest are optional. But when you fill out the form (even completely) and click Join, you get the message box, and it sends you back.
-
May 13, 2003, 18:10 #9
- Join Date
- Apr 2001
- Location
- Canada
- Posts
- 5,458
- Mentioned
- 1 Post(s)
- Tagged
- 0 Thread(s)
Is the form set to POST?
PHP Code:if ( $_POST['username'] == "" || $_POST['password'] == "" || $_POST['email'] == "" ) {
error("One or more of the required fields were left blank. \n Please fill them in and try again." );
}
Mike
It's not who I am underneath, but what I do that defines me.
-
May 13, 2003, 18:26 #10
Thank you (again) for that, but I've figured out (by using different error messages) that the problem deals with this part of the script:
PHP Code:$sql = "INSERT INTO design_users SET
username='$username',
password='$password',
email='$email',
aim='$aim',
icq='$icq',
msn='$msn',
date_joined=CURDATE,
age='$age',
interests='$interests',
job='$job',
website='$website',
websiteurl='$websiteurl',
websitedescription='$websitedescription'";
if (!mysql_query($sql))
error("An internal error has occurred in processing your ".
"submission.\\nIf this message continues after you try again, please email me at [email=koomann@star-craftx.com]koomann@star-craftx.com[/email]");
}
-
May 13, 2003, 18:35 #11
Hold on, a friend told me I had the wrong syntax, that it needed to look like this:
PHP Code:$sql = "INSERT INTO design_users
(username, password, email, aim, icq, msn, date_joined, age, interests, job, website, websiteurl, websitedescription) VALUES ('username', 'password', 'email', 'aim', 'icq', 'msn', 'DATETIME', 'age', 'interests', 'job', 'website', 'websiteurl', 'websitedescription')";
-
May 13, 2003, 18:39 #12
- Join Date
- Apr 2001
- Location
- Canada
- Posts
- 5,458
- Mentioned
- 1 Post(s)
- Tagged
- 0 Thread(s)
EDIT you got it, nevermind
Mike
It's not who I am underneath, but what I do that defines me.
-
May 13, 2003, 20:15 #13
Bookmarks