Page 1 of 1

PHP Help Needed Immediately

Posted: Fri Apr 16, 2004 3:34 pm
by prithvim
hi guys,
i need some help with thi script that i just wrote in PHP. actually it is my first script but i was pretty confident that it would work well.
but only the register.php and login.php pages are loading.
in everything else there is an error message saying error while parsing on line 3 for all scripts.
the scripts are for a blog. they are located at :

http://www.prithvidesign.com/blogtest/

and all the files are in the zip file in the same folder.
please help me out.

Posted: Fri Apr 16, 2004 3:41 pm
by qads
you may wanna post your code, i.e, what is on line 3?

Posted: Fri Apr 16, 2004 3:43 pm
by feyd
I only looked at signup.php and login.php, but in signup, you have

Code: Select all

<? php
it should be

Code: Select all

<?php

Posted: Fri Apr 16, 2004 3:53 pm
by steve2004
Had quick look at some of scripts
need to use

session_start();
session_register('username');

error code

Posted: Fri Apr 16, 2004 4:03 pm
by prithvim

Code: Select all

Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' in /home/prithvim/public_html/blogtest/signup.php on line 14
this is the latest error code i am getting after making a few changes

Posted: Fri Apr 16, 2004 4:11 pm
by Steveo31
steve2004 wrote:Had quick look at some of scripts
need to use

session_start();
session_register('username');
PHP.net says _register is deprecated.

Posted: Fri Apr 16, 2004 4:17 pm
by steve2004
fair comment steveo

php version?

Posted: Fri Apr 16, 2004 4:24 pm
by prithvim
mine is 4.3.4 i guess

Posted: Fri Apr 16, 2004 4:58 pm
by steve2004
debug
try echo variables when in functions see what values they have, helps track down bugs also try

global vars

hope this helps!

Posted: Fri Apr 16, 2004 5:14 pm
by prithvim
these are the two scripts that i am using:

Code: Select all

<html>
<head>
<title>New User Registration</title>
</head>
<body>
<div>
<form action="signup.php" method="post">
<p>
Desired UserID: <input type="text" name="userid" length="8" size="8"><br>
Password: <input type="password" name="password" length="8" size="8"><br>
Full Name: <input type="text" name="name" length="25" size="25"><br>
Email: <input type="text" name="email" length="50" size="50"><br>
</p>
<input type="reset" value="Reset">&nbsp;&nbsp;
<input type="submit" value="Submit">
<p>
<b>Note: All fields are mandatory.</b>
</p>
</form>
</div>
</body>
</html>
and

Code: Select all

<?php

if ( !empty($_POST&#1111;'userid']) && !empty($_POST&#1111;'password']) && !empty($_POST&#1111;'name']) && !empty($_POST&#1111;'email']) )
	&#123;
		check_userid();
	&#125;
else
	&#123;
		die("<b>Please go back and fill in all the fields.</b>");
	&#125;

function check_userid()
	&#123;
		if(file_exists("$_POST&#1111;userid].txt"))
			&#123;
				die("The UserID <b>$_POST&#1111;userid]</b> already exists.<br/>Please choose another UserID.");
			&#125;
		else
			&#123;
				create_file();
			&#125;
	&#125;

function create_file()
	&#123;
		touch("$_POST&#1111;userid].txt");
		if($fp=fopen("$_POST&#1111;userid].txt","w"))
			&#123;
				create_userid();
			&#125;
		else
			&#123;
				die("There was an error processing your request.<br/>Please try again later.");
			&#125;
	&#125;
function create_userid()
	&#123;
		if(fwrite($fp,"$_POST&#1111;userid]\n$_POST&#1111;password]\n$_POST&#1111;name]\n$_POST&#1111;email]\n"))
			&#123;
				fclose($fp);
				die("UserID <b>$_POST&#1111;userid]</b> successfully created.");
			&#125;
		else
			&#123;
				die("There was an error processing your request.<br/>Please try again later.");
			&#125;
	&#125;

?>
and this is the error message:

Code: Select all

Warning: fwrite(): supplied argument is not a valid stream resource in /home/prithvim/public_html/blogtest/signup.php on line 38
There was an error processing your request.
Please try again later.

Posted: Fri Apr 16, 2004 5:22 pm
by feyd
$fp isn't globally available. Should probably return it from create_file() and pass it to create_userid()

Posted: Fri Apr 16, 2004 5:41 pm
by prithvim
how do i do that?

Posted: Fri Apr 16, 2004 5:49 pm
by feyd
change

Code: Select all

create_userid();
in create_file() to

Code: Select all

create_userid($fp);
then change

Code: Select all

function create_userid()
to

Code: Select all

function create_userid($fp)

Posted: Fri Apr 16, 2004 6:25 pm
by prithvim
hey thanks a lot guys.
now the first part of the script is working.
guess i'll be able to manage the rest of them myself.
anyway...u will seeing more of me here.