|
-
Jul 20th, 2005, 01:09 AM
#1
Thread Starter
Admodistrator
[RESOLVED] Parse error again..
PHP Code:
<html>
<h3>Testing Stuff</h3>
<form method = "POST" action ="<?php echo $_SERVER['PHP_SELF'];?>"
<input type = "hidden" name = "send" value = "1">
<p>Username:<input type="text" name="UserName" /></p>
<p>Password:<input type="text" name="Password" /></p>
<input type="submit" value ="Login" />
</form>
<body background="http://users.pandora.be/creeping_death/Babes/Anna%20Kournikova%2002.jpg">
<?php
If ($_POST[send] == "1"){
$Filename = $_POST[UserName];
If (file_exists($Filename)){
$handle = fopen($Filename, "r") or die("Error Reading");
$contents = @fread($handle,filesize($Filename)) or die("Error2");
fclose($handle);
If ($contents == $_POST[Password]){
echo "</br>.Logged in";
}else{
echo "Invalid password";
}
[B]}else{[/B]
$handle = fopen($Filename, "w") or die ("Error writing");
$contents = @fwrite($handle,$_POST[Password];
fclose($handle);
}
?>
</html>
says error on line 25, and i really dont see anything wrong there
-
Jul 20th, 2005, 01:16 AM
#2
Re: Parse error again..
is the error on the supposed to be bolded part else?
-
Jul 20th, 2005, 01:17 AM
#3
Re: Parse error again..
I think you have forgot to close fwrite function? on teh else part.
-
Jul 20th, 2005, 01:19 AM
#4
Re: Parse error again..
and I'm not seeing the closing parenthesis of your very first if. block
-
Jul 20th, 2005, 02:00 AM
#5
Thread Starter
Admodistrator
Re: Parse error again..
Code:
If ($_POST[send] == "1"){
$Filename = $_POST[UserName];
If (file_exists($Filename)){
$handle = fopen($Filename, "r") or die("Error Reading");
$contents = @fread($handle,filesize($Filename)) or die("Error2");
fclose($handle);
If ($contents == $_POST[Password]){
echo "</br>.Logged in";
}else{
echo "Invalid password";
}
}else{
$handle = fopen($Filename, "w") or die ("Error writing");
$contents = @fwrite($handle,$_POST[Password];
fclose($handle);
}
Also, what did you mean i am not closing my fwrite?
$contents = @fwrite($handle,$_POST[Password];
fclose($handle);
-
Jul 20th, 2005, 02:40 AM
#6
Re: Parse error again..
$contents = @fwrite($handle,$_POST[Password]); <<-- closing parenthesis
-
Jul 21st, 2005, 12:32 AM
#7
Thread Starter
Admodistrator
Re: Parse error again..
OB, can i ask one more:
PHP Code:
<html>
<h3>Testing Site</h3>
<form method = "POST" action = "<?php echo $_SERVER['PHP_SELF'];?>"
<input type = "hidden" name = "hidden" value = "1"/>
<p>UserName<input type = "text" name = "UserName"/></p>
<p>Password<input type = "text" name = "Password"/></p>
</form>
<body background="http://users.pandora.be/creeping_death/Babes/Anna%20Kournikova%2002.jpg>
<?php
If($_POST[hidden]=="1"){
$filename = $_POST[UserName.".html"]
If(file_exists($filename)){
$handle = fopen($filename,"r") or die("Err1")
$contents = @fread($handle,filesize($filename))
flcose($handle)
}Else{
If($contents ==$_POST[Password]){
echo "Logged in"
}Else{
echo "Invalid password"
}
echo "Username created!"
$handle = fopen($filename,"w") or die("Err2")
fwrite($handle,$_POST[Password])
}
}
?>
Its giving me this error:
Parse error: syntax error, unexpected T_IF in C:\Documents and Settings\Jason\My Documents\PHP\Login Script\_debug_tmp.php on line 12
line 12= If(file_exists($filename)){
So i dont know whats wrong (whats new )
-
Jul 21st, 2005, 12:54 AM
#8
Hyperactive Member
Re: Parse error again..
jason i heart u
-
Jul 21st, 2005, 01:08 AM
#9
Hyperactive Member
Re: Parse error again..
u forgot to put the ; after everything, try doin that
-
Jul 21st, 2005, 01:25 AM
#10
Thread Starter
Admodistrator
Re: Parse error again..
okay got everything almost working.
PHP Code:
<html>
<h3>Testing Site</h3>
<form method = "POST" action = "<?php echo $_SERVER['PHP_SELF'];?>"
<input type = "hidden" name = "send" value = "1">
<p>UserName<input type = "text" name = "UserName"/></p>
<p>Password<input type = "text" name = "Password"/></p>
<input type="submit" value ="Login" />
</form>
<body background="http://users.pandora.be/creeping_death/Babes/Anna%20Kournikova%2002.jpg">
</body>
<?php
If($_POST[send]=="1"){
$filename = $_POST[UserName.".txt"];
If(file_exists($filename)){
$handle = fopen($filename,"r") or die("Err1");
$contents = @fread($handle,filesize($filename));
fclose($handle);
}Else{
If($contents ==$_POST[Password]){
echo "Logged in";
}Else{
echo "Invalid password";
}
echo "Username created!";
$handle = fopen($filename,"w") or die("Err2");
fwrite($handle,$_POST[Password]);
fclose($handle);
}
}
?>
</html>
I keep getting errors on this line: If($_POST[send]=="1"){
Notice: Use of undefined constant send - assumed 'send' in C:\Documents and Settings\Jason\My Documents\PHP\Login Script\_debug_tmp.php on line 12 Notice: Undefined index: send in C:\Documents and Settings\Jason\My Documents\PHP\Login Script\_debug_tmp.php on line 12
-
Jul 21st, 2005, 01:31 AM
#11
Re: Parse error again..
perhaps send needs to be a string...
I really thought that in that context.. and send being used that way... it will look for a constant variable.. which is not defined. and perhaps that's where the error goes...
I would use this.. instead of that.
If($_POST['send']=="1"){
or
If($_POST["send"]=="1"){
-
Jul 21st, 2005, 01:34 AM
#12
Thread Starter
Admodistrator
Re: Parse error again..
Okay thanks, but now this part is still there:
Notice: Undefined index: send in C:\Documents and Settings\Jason\My Documents\PHP\Login Script\_debug_tmp.php on line 12
I dont understand that..Also, whats the difference between using [name] and ['name] and ["name"]
-
Jul 21st, 2005, 01:35 AM
#13
Re: Parse error again..
may I comment on this code fragment?
$filename = $_POST[UserName.".txt"];
are you sure about this one?.. this will definitely give you a very weird output.
i think the right one would be.
$filename = $_POST[UserName].".txt";
notice how the ".txt" is moved outside of the brackets?.... I think this is what you want.. 'cause I don't see you posting a value for.... someusername.txt
-
Jul 21st, 2005, 01:40 AM
#14
Thread Starter
Admodistrator
Re: Parse error again..
yes you are right, im still a beginner with php..just learning.
Thanks, but im still getting that dumb error^^
-
Jul 21st, 2005, 01:42 AM
#15
Re: Parse error again..
I think $_POST['send'] and $_POST["send"] is pretty much the same.. they delimit strings... now if you had posted a value like... send'ed your way of accessing the value would have be $_POST["send'ed"] and vice versa..
now for $_POST[send] I read at the dox.. and perhaps it is the right one.. but better ask the gurus for this one... that.. the send part here will be accessing a constant variable.. that is defined this way on the file or else where (just included it)...
define("send", "somesendvalue");
so the $_POST[send] in my example would actually be accessing like
$_POST["somesendvalue"]
well at least that is my understanding of... it. I do hope that someone could clear this up.
-
Jul 21st, 2005, 01:44 AM
#16
Re: Parse error again..
I guess my theory holds on the send... I think it is looking up a constant value... perhaps you could try to change all send variable that you want?
-
Jul 21st, 2005, 01:46 AM
#17
Re: Parse error again..
Just try to change all you $_POST statement... like the send, UserName, Password... enclosed in string delimiters(am I using the right term).. and see from there?
-
Jul 21st, 2005, 01:49 AM
#18
Re: Parse error again..
 Originally Posted by ninjanutz
jason i heart u 
who is jason?
-
Jul 21st, 2005, 01:49 AM
#19
Thread Starter
Admodistrator
Re: Parse error again..
Thanks again
PHP Code:
<html>
<h3>Testing Site</h3>
<form method = "POST" action = "<?php echo $_SERVER['PHP_SELF'];?>"
<input type = "hidden" name = "send" value = "1">
<p>UserName<input type = "text" name = "UserName"/></p>
<p>Password<input type = "text" name = "Password"/></p>
<input type="submit" value ="Login" />
</form>
<body background="http://users.pandora.be/creeping_death/Babes/Anna%20Kournikova%2002.jpg">
</body>
<?php
If($_POST['send']=="1"){
$filename = $_POST['UserName'].".txt";
If(file_exists($filename)){
$handle = fopen($filename,"r") or die("Err1");
$contents = @fread($handle,filesize($filename));
fclose($handle);
}Else{
If($contents ==$_POST['Password']){
echo "Logged in";
}Else{
echo "Invalid password";
}
echo "Username created!";
$handle = fopen($filename,"w") or die("Err2");
fwrite($handle,$_POST['Password']);
fclose($handle);
}
}
?>
</html>
Still the same error on line 12 (index error)
-
Jul 21st, 2005, 01:51 AM
#20
Re: Parse error again..
 Originally Posted by error
I keep getting errors on this line: If($_POST[send]=="1"){
Notice: Use of undefined constant send - assumed 'send' in C:\Documents and Settings\Jason\My Documents\PHP\Login Script\_debug_tmp.php on line 12 Notice: Undefined index: send in C:\Documents and Settings\Jason\My Documents\PHP\Login Script\_debug_tmp.php on line 12
ahh I see it now.. it IS definitely looking for a constant value send... so my theory holds.
-
Jul 21st, 2005, 01:53 AM
#21
Re: Parse error again..
really? hmm.. weird..
well on my code.. I used.. the " and didn't get to try ' actually... I wonder if that would do it.... have you refreshed everything?? saved everything.?
-
Jul 21st, 2005, 01:55 AM
#22
Re: Parse error again..
Uhmmm I just noticed.. in your opening tag for FORM.. there is not closing > would that be alright?
perhaps the form did not get submitted or something.
-
Jul 21st, 2005, 01:56 AM
#23
Thread Starter
Admodistrator
Re: Parse error again..
Yes, ive tried both and none resolve im stumped
-
Jul 21st, 2005, 01:58 AM
#24
-
Jul 21st, 2005, 02:00 AM
#25
Re: Parse error again..
I'm going to try this one here locally.
-
Jul 21st, 2005, 02:04 AM
#26
Re: Parse error again..
HEEY!!!!.. HOW COME IT WORKED ON MINE... and I didn't even change the code.. the last one that is.
-
Jul 21st, 2005, 02:09 AM
#27
Re: Parse error again..
and disregard my other question.. I found out that your page indeed worked.. I learn new things everyday. tnx.
-
Jul 21st, 2005, 02:09 AM
#28
Thread Starter
Admodistrator
Re: Parse error again..
can i see the code you tried?
-
Jul 21st, 2005, 02:12 AM
#29
Re: Parse error again..
sure! here it is...
I changed the file location.. so that I can just look at the c root and see if indeed the file got created.. and it did. 
PHP Code:
<html>
<h3>Testing Site</h3>
<form method = "POST" action = "<?php echo $_SERVER['PHP_SELF'];?>">
<input type = "hidden" name = "send" value = "1">
<p>UserName<input type = "text" name = "UserName"/></p>
<p>Password<input type = "text" name = "Password"/></p>
<input type="submit" value ="Login" />
</form>
<body background="http://users.pandora.be/creeping_death/Babes/Anna%20Kournikova%2002.jpg">
</body>
<?php
If($_POST['send']=="1"){
$filename = "c:\\".$_POST['UserName'].".txt";
If(file_exists($filename)){
$handle = fopen($filename,"r") or die("Err1");
$contents = @fread($handle,filesize($filename));
fclose($handle);
}Else{
If($contents ==$_POST['Password']){
echo "Logged in";
}Else{
echo "Invalid password";
}
echo "Username created!";
$handle = fopen($filename,"w") or die("Err2");
fwrite($handle,$_POST['Password']);
fclose($handle);
}
}
?>
</html>
-
Jul 21st, 2005, 02:15 AM
#30
-
Jul 21st, 2005, 02:26 AM
#31
Thread Starter
Admodistrator
Re: Parse error again..
Same error as before??
Notice: Undefined index: send in C:\Documents and Settings\Jason\My Documents\PHP\Login Script\_debug_tmp.php on line 12
And also, if i run it differently (Im using php Designer 2005 IDE) the submit field doesnt remain on the first page
-
Jul 21st, 2005, 02:29 AM
#32
Re: Parse error again..
hmmm.. I wonder why... I edited it at notepad, pasted it on htdocs root.. then opened a browser.. pointed it to the page.. and it worked fine. perhaps php designer not refreshing or something.
-
Jul 21st, 2005, 02:33 AM
#33
Re: Parse error again..
I'm sorry I can't do nothing more than that... it is working well here 
in fact.. it even works fine without them string delimiters.
-
Jul 21st, 2005, 02:42 AM
#34
Thread Starter
Admodistrator
Re: Parse error again..
Well, it works in xampp but not this ide..Guess i should get a better IDE.
Also, im getting this error when creating password and stuff on line 25
$handle = fopen($filename,"w") or die("Err2");
Warning: fopen(|2eM!x.txt): failed to open stream: Invalid argument in C:\PHP\xampp\htdocs\xampp\newform.php on line 25
Err2
-
Jul 21st, 2005, 02:51 AM
#35
Re: Parse error again..
Perhaps... the file name shouldn't have invalid characters like..| or ! ???
-
Jul 21st, 2005, 02:52 AM
#36
Re: Parse error again..
why can't you give it a simpler name??? it worked fine here. lol my names are like 1 and 2.. so that would be 1.txt and 2.txt... it was generated.
and go get a better IDE.
-
Jul 21st, 2005, 12:21 PM
#37
Thread Starter
Admodistrator
Re: Parse error again..
That makes sense. Thankyou oceanbelle for helping me!
-
Jul 21st, 2005, 07:47 PM
#38
Re: [RESOLVED] Parse error again..
glad to help.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|