(!) Parse error...

Place for questions and answers for all newcomers and new coders. This is a free for all forum, no question is too stupid and to noob.
Post Reply
PaleSins
Posts: 5
Joined: Sat May 19, 2012 1:53 am

(!) Parse error...

Post by PaleSins »

While following the tutorial videos, on video 3b this is the error message after the info is submitted and the page is loaded:

( ! ) Parse error: syntax error, unexpected T_ECHO in C:\wamp\www\Tutorial\reguser.php on line 15

This is the area of coding that is the problem, but I dont see what's wrong.

<?php
include 'connect.php';
?>

<?php
$player=$_POST['player'];
$password=$_POST['password'];
$password2=$_POST['password2'];
$player=strip_tags($player);
$email=$_POST['email'];
$email=strip_tags($email);

if ($email == "")
(
echo "You didn't enter an email address!<br>";
echo " <a href='register.php'>Go back</a>";
exit;
)


This is my 1st attempt to learn php but it seems that the ; isn't doing it's job in line 14...
Can someone please help me out here? Thank you very much! :)
PaleSins
Posts: 5
Joined: Sat May 19, 2012 1:53 am

Re: (!) Parse error...

Post by PaleSins »

I changed the ECHO to PRINT and now this is the error message I get:

( ! ) Parse error: syntax error, unexpected ';' in C:\wamp\www\Tutorial\reguser.php on line 15

This is the coding and you see I changed ECHO to PRINT:

<?php
include 'connect.php';
?>

<?php
$player=$_POST['player'];
$password=$_POST['password'];
$password2=$_POST['password2'];
$player=strip_tags($player);
$email=$_POST['email'];
$email=strip_tags($email);

if ($email == "")
(
print "You didn't enter an email address<br>";
print " <a href='register.php'>Go back</a>";
exit;
)

I know I am doing something wrong I just can't figure out what it is...
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: (!) Parse error...

Post by Jackolantern »

You are using the wrong kind of bracket for your IF statement:

Code: Select all

if ($email == "")
(
print "You didn't enter an email address<br>";
print " <a href='register.php'>Go back</a>";
exit;
) 
Should be...

Code: Select all

if ($email == "")
{
print "You didn't enter an email address<br>";
print " <a href='register.php'>Go back</a>";
exit;
} 
{ } make a code block. Typically anytime you have multiple statements (or the chance to have multiple statements) inside the brackets, like inside IF, WHILE, FOR loops, functions, etc., you need to use { }. ( ) are used for function calls, and for the condition of IF statements, WHILE and FOR loops, etc. (for example, the ($email == "") part in the above code is right).

Anytime you get a T_ECHO error, syntax or parse error, the first thing to check is if you have something that just doesn't belong, like you forgot to put a semicolon after a statement, used the wrong bracket or something like that. 8-)
The indelible lord of tl;dr
PaleSins
Posts: 5
Joined: Sat May 19, 2012 1:53 am

Re: (!) Parse error...

Post by PaleSins »

Wow! That is amazing! Thank you!
Watching the videos it was hard to see all the characters he had typed. Since he had it typed before the video started, to shorten the video length I didnt see him enter it and he never specified that it was {} and the difference between them. I totally get it now. It make so much sense. Again thank you. HTML seemed easier to learn but longer to write. I like php :)
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: (!) Parse error...

Post by Jackolantern »

Yes, HTML is much easier to learn than PHP, since HTML is just a mark-up language and not a real programming language.

And don't worry about the mistake. You are about the 20th person who has made the same mistake lol. Once the videos were uploaded to YouTube, the quality will make them a bit blurry and hard to decipher lol. 8-)
The indelible lord of tl;dr
PaleSins
Posts: 5
Joined: Sat May 19, 2012 1:53 am

Re: (!) Parse error...

Post by PaleSins »

Wow, I ran into another roadblock rather fast. Ive been trying since the last post to figure this out.
This is the error message:

( ! ) Fatal error: Call to undefined function strien() in C:\wamp\www\Tutorial\reguser.php on line 31
Call Stack
# Time Memory Function Location
1 0.0156 384864 {main}( ) ..\reguser.php:0

This is the coding:

<?php
include 'connect.php';
?>

<?php
$player=$_POST['player'];
$password=$_POST['password'];
$pass2=$_POST['pass2'];
$player=strip_tags($player);
$email=$_POST['email'];
$email=strip_tags($email);

if ($email == "")
{
print "You didn't enter a email address!<br>";
print " <a href='register.php'>Go back</a>";
exit;
}
if ($password==$pass2)
{
$isplayer="SELECT * from players where name='$player'";
$isplayer2=mysql_query($isplayer) or die("Could not query player's table.");
$isplayer3=mysql_fetch_array($isplayer2);

if(!$_POST['password'] || !$_POST['pass2'])
{
print "You didn't enter a password!<br>";
print " <a href='register.php'>Go back</a>";
exit;
}
else if($isplayer3 || strien($player)>21 || strien($player)<1)
{
print "There is already a player with that name or the name you specified is over 21 leters or less that 1 letter<br>";
print " <a href='register.php'>Go back</a>";
exit;
}
else
{
$isaddress="SELECT * from players where email='$email'";
$isaddress2=mysql_query($isaddress) or die("not able to query for password");
$isaddress3=mysql_fetch_array($isaddress2);
if ($isaddress3)
{
print "There is already a player with that email address.<br>";
print " <a href='register.php'>Go back</a>";
exit;
}
else
{
$password=md5 ($password);

$SQL = "INSERT into players(name, password, email, level, exper) VALUES ('$player','$password','$email','1','0')";
mysql_query($SQL) or die("could not register");

print "Thank you for registering!";
}
}
}

else
{
print "Your password didn't match or you did not enter a password.<br>";
print " <a href='register.php'>Go back</a>";
exit;
}
print " <a href='login.php'>Login Page</a><br>";

?>


I know the problem is somewhere in the ELSE IF statement. I have even checked the register form to make sure it all matches.
This is the form coding:
<?php
include 'connect.php';

?>

<form method ="post" action="reguser.php">
Type Username Here: <input type="text" name="player" size "21"><br>
Type Password Here: <input type="text" name="password" size "15"><br>
ReType Password Again: <input type="text" name="pass2" size "15"><br>
Type Email Address: <input type="text" name="email" size "60"><br>

<input type="submit" value="submit">

Im really lost...
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: (!) Parse error...

Post by Jackolantern »

It looks like another case of the YouTube blurs :)

Code: Select all

else if($isplayer3 || strien($player)>21 || strien($player)<1) 
Should be...

Code: Select all

else if($isplayer3 || strlen($player)>21 || strlen($player)<1) 
The function is strlen(), short for "string length". It returns the number of characters in the string.

And I figured I would say that the typical community opinion is that it is better to simply watch all the videos up until 14 first, without typing a line of code. Then go back and start following along, typing in the code. This is because a lot of things are incomplete and will not function until that point, and also because you will have a much better sense about programming after watching up to that point and will be better armed to debug and handle issues such as these. Of course you can start coding right from video one, but not knowing what will work, when certain systems will be finished, and just all of the debugging work you will have to do will likely be painful. ;)
The indelible lord of tl;dr
PaleSins
Posts: 5
Joined: Sat May 19, 2012 1:53 am

Re: (!) Parse error...

Post by PaleSins »

Yeah I feel about half stupid after that. hahaha I think Ima take your advice. It probably would be easier to fix things after Ive watched and learned some.
Thank you. I really do appreciate it.
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: (!) Parse error...

Post by Jackolantern »

Don't feel stupid about it! No matter how it may seem, nobody here was born being able to code lol. It is a difficult thing to do, and it takes time to get proficient at it. Watching the videos through once (at least to video 14, if not all the way through the available videos) will make things go a lot smoother. You will also have a better idea of how you want your final game to differ from the tutorial game, and a more clear plan on how you will make those changes after you have watched the tutorial series without writing code (this is why I say it may be a good idea to watch the whole thing through before writing any code). Best of luck with it! :)
The indelible lord of tl;dr
Post Reply

Return to “Beginner Help and Support”