Page 1 of 1

User Creation

Posted: Fri Sep 28, 2007 11:47 am
by z0
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hi all,:) 
I am getting error when trying to run this code!!
The code is:

Code: Select all

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<?php
//register.php
include_once "./common_db.inc";
function in_use($userid)
{
global $user_tablename;
$query="SELECT userid FROM $user_tablename WHERE userid='$userid'";
$result=mysql_query($query);
if(!mysql_num_rows($result)){
return 0;
}else{
return 1;
}
}
function register_form()
{
global $userposition;
global $PHP_SELF;
$link_id=db_connect();
$link_id=db_connect();
mysql_select_db("sample_db");
$position_array=enum_options('userposition',$link_id);
mysql_close($link_id);
?>
<center><h3>Create your account!</h3></center>
<form method="post" action="<?php echo $PHP_SELF ?>">
<input type="hidden" name="action">
<div align="center"><center><table border="1" width="90%">
<tr>
<th width="30%" nowrap>Desired ID</th>
<td width="70%"><input type="text" name="userid" size=8"></td>
</tr>
<tr>
<th width="30%" nowrap>Desired Password</th>
<td WIDTH="70%"><input type="password" name="userpassword2" size="15"></td>
</tr>
<tr>
<th width="30%" nowrap>Full Name</th>
<td width="70%"><input type="text" name="username" size="20"></td>
</tr>
<tr>
<td width="30%" nowrap>Position</th>
<td width="70%"><select name="userposition" size="1">
<?php

?>
for($i=0;$i<count($position_array);$i++){
if(!isset($userposition) && $i==0){
echo "<OPTION SELECTED VALUE=\"".$position_array[$i]."\">".$position_array[$i]."</OPTION>\n";
}else if($userposition==$cposition_array[$i]){
echo "<OPTION SELECTED VALUE=\"".$position_array[$i]."\">".
$position_array[$i]."</td>OPTION>\n";
}
}
?>
</select></td>
</tr>
<tr>
<th width="30%" nowrap>Email</th>th>
<td width="70%"><input type="text" name="useremail" size="20"
</td>
</tr>
<tr>
<th width="30%" nowrap>Profile</th>th>
<td WIDTH="70%"><textarea rows="5" cols="40" name="userprofile"></textarea>textarea></tr>
</tr>
<tr>
<th width="30%" colspan="2" nowrap="nowrap">
<input type="submit" value="Submit" />
<input type="reset" value="Reset" /></th>
</tr>
</table>
</center>
</div>
</form>
<?php
}
function create_account()
{
$userid=$_POST['userid'];
$username=$_POST['username'];
$userpassword=$_POST['userpassword'];
$userpassword2=$_POST['userpassword2'];
$userposition=$_POST['userposition'];
$useremail=$_POST['useremail'];
$userprofile=$_POST['userprofile'];
global $default_dbname,$user_tablename;
if(empty($userid)){
error_message("Enter yur desired ID!");
}
if(empty($userpassword)){
error_message("Enter your password!");
}
if(strlen($userpassword)<4){
error_message("Password too short!");
}
if(empty($userpassword2)){
error_message("Retype your password for verification");
}
if(empty($username)){
error_message("Enter your full name:");
}
if(empty($useremail)){
error_message("Enter your email address!");
if(empty($userprofile)){
$userprofile="No comment";
}
if($userpassword!=$userpassword2){
error_message("your desired password and retyped password mismatch!");
}
$link_id=db_connect($default_dbname);
if(in_use($userid)){
error_message("userid is in use.Please choose a different ID");
$query="INSERT INTO user VALUES(NULL,'$userid',password('$userpassword')'$username','$userposition','$useremail','$userprofile')";
$result=mysql_query($query);
if($result){
error_message(sql_error());
}
$usernumber=mysql_insert_id($link_id);
html_header(sql_error());
}
$usernumber=mysql_insert_id($link_id);
html_header();
?>
<center><h3>
<?php echo $username ?>,thank you for registering with us!
</h3></center>
<div align="center"><center><table border="1" width="90%">
<tr>
<th width="30%" nowrap>User Number</th>
<td width="70%"><?php echo $usernumber ?></td>
</tr>
<tr>
<th width="30%" nowrap>Desired ID</th>
<td width="70%"><?php echo $userid ?>jhjkkkjkh</td>
</tr>
<tr>
<th width="30%" nowrap>Desired Password</th>
<td width="70%"><?php echo $userpassword?></td>
<tr>
<th width="30%" nowrap>Full name</th>th>
<td width="70%"><?php echo $username ?></td>
</tr>
<tr>
<th width="30%" nowrap>Position</th>
<td width="70%"><?php echo $userposition ?></td>
</tr>
<tr>
<th width="30%" nowrap>Email</th>
<td width="70%"><?php echo $useremail ?></td>
<th width="30%" nowrap>Profile</th>
<td width="30%" nowrap><?php echo htmlspecialchars($userprofile) ?></td>
</tr>
</table>
</center></div>
<?php
 html_footer();
 }
 if(empty($_POST)){
 $_POST['action']="";
 }
 switch($_POST['action']){
 case "register":
 create_account();
 break;
 default:
 html_header();
 register_form();
 html_footer();
 break;
 }
 ?>
 </form>
 </body>
 </html>
Why is it giving this error--
Parse error: syntax error, unexpected $end in C:\xxx\www\test\create.php on line 182
:?
How to rectify the error?
Please help...
Thanks in advance


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Fri Sep 28, 2007 11:57 am
by feyd
Count the number of opening and closing braces your code has. Mostly likely, there is a mismatch.

Posted: Fri Sep 28, 2007 8:31 pm
by Josh1billion
feyd wrote:Count the number of opening and closing braces your code has. Mostly likely, there is a mismatch.
Also, to add onto that, if you use Notepad++ (google it, it's a very good text editor), you can see your { and } braces match up when you click on them, so it makes it much easier to make sure they all match.

Posted: Fri Sep 28, 2007 8:58 pm
by s.dot
To expand, indenting (tabbing or spacing) your code would help you visually identify where the braces don't match up. PHP and HTML. And, it's a good practice.

re:user create

Posted: Fri Sep 28, 2007 10:18 pm
by z0
:(
But still I am getting error-
Parse error: syntax error, unexpected $end in C:\wamp\www\test\cr1.php on line 182
What does this " unexpected $end" means??
Apart from braces mismatching, are there no other errors?I mean,is the code perfect?
:roll:

Posted: Sat Sep 29, 2007 1:14 am
by Hemlata
Hello,

You are missing with the closing brace for the function 'function create_account()'.

Hope this might solve your issue.
Regards

re:createuser

Posted: Sat Sep 29, 2007 4:32 am
by z0
Hi, :)
You are missing with the closing brace for the function 'function create_account()'.
But I have given the closing brace!!

Code: Select all

function create_account()
{
$userid=$_POST['userid'];
$username=$_POST['username'];
$userpassword=$_POST['userpassword'];
$userpassword2=$_POST['userpassword2'];
$userposition=$_POST['userposition'];
$useremail=$_POST['useremail'];
$userprofile=$_POST['userprofile'];
global $default_dbname,$user_tablename;
if(empty($userid)){
error_message("Enter yur desired ID!");
}
if(empty($userpassword)){
error_message("Enter your password!");
}
if(strlen($userpassword)<4){
error_message("Password too short!");
}
if(empty($userpassword2)){
error_message("Retype your password for verification");
}
if(empty($username)){
error_message("Enter your full name:");
}
if(empty($useremail)){
error_message("Enter your email address!");
if(empty($userprofile)){
$userprofile="No comment";
}
if($userpassword!=$userpassword2){
error_message("your desired password and retyped password mismatch!");
}
$link_id=db_connect($default_dbname);
if(in_use($userid)){
error_message("userid is in use.Please choose a different ID");
$query="INSERT INTO user VALUES(NULL,'$userid',password('$userpassword')'$username','$userposition','$useremail','$userprofile')";
$result=mysql_query($query);
if($result){
error_message(sql_error());
}
$usernumber=mysql_insert_id($link_id);
html_header(sql_error());
}
Where is the brace missing in the above code?
:roll:
Can you please point me the line number in the above code?

Posted: Sat Sep 29, 2007 4:50 am
by Hemlata
Hello,

Paste your previous code in text-editor and give proper tabbing in order to check for the missing braces or closing tags. See below code related with your last function, here you have missed 2 closings..

Code: Select all

<?php
function create_account()
{
	$userid=$_POST['userid'];
	$username=$_POST['username'];
	$userpassword=$_POST['userpassword'];
	$userpassword2=$_POST['userpassword2'];
	$userposition=$_POST['userposition'];
	$useremail=$_POST['useremail'];
	$userprofile=$_POST['userprofile'];
	global $default_dbname,$user_tablename;
	if(empty($userid))
	{
		error_message("Enter yur desired ID!");
	}
	if(empty($userpassword))
	{
		error_message("Enter your password!");
	}
	if(strlen($userpassword)<4)
	{
		error_message("Password too short!");
	}
	if(empty($userpassword2))
	{
		error_message("Retype your password for verification");
	}
	if(empty($username))
	{
		error_message("Enter your full name:");
	}
	if(empty($useremail))
	{
		error_message("Enter your email address!");
		if(empty($userprofile))
		{
			$userprofile="No comment";
		}
		if($userpassword!=$userpassword2)
		{
			error_message("your desired password and retyped password mismatch!");
		}
		$link_id=db_connect($default_dbname);
		if(in_use($userid))
		{
			error_message("userid is in use.Please choose a different ID");
			$query="INSERT INTO user VALUES(NULL,'$userid',password('$userpassword')'$username','$userposition','$useremail','$userprofile')";
			$result=mysql_query($query);
			if($result)
			{
				error_message(sql_error());
			}
			$usernumber=mysql_insert_id($link_id);
			html_header(sql_error());
		}
?>
Hope this will help you.
Regards,

re:user create

Posted: Sat Sep 29, 2007 5:40 am
by z0
No I am still getting this error- :(

Parse error: syntax error, unexpected $end in C:\xxx\www\test\crea3.php on line 193

p.s. :Line 192 is </html>

Posted: Sat Sep 29, 2007 5:50 am
by Hemlata
You, didnot got my point. Replace your function with the following ..

Code: Select all

<?php
function create_account()
{
        $userid=$_POST['userid'];
        $username=$_POST['username'];
        $userpassword=$_POST['userpassword'];
        $userpassword2=$_POST['userpassword2'];
        $userposition=$_POST['userposition'];
        $useremail=$_POST['useremail'];
        $userprofile=$_POST['userprofile'];
        global $default_dbname,$user_tablename;
        if(empty($userid))
        {
                error_message("Enter yur desired ID!");
        }
        if(empty($userpassword))
        {
                error_message("Enter your password!");
        }
        if(strlen($userpassword)<4)
        {
                error_message("Password too short!");
        }
        if(empty($userpassword2))
        {
                error_message("Retype your password for verification");
        }
        if(empty($username))
        {
                error_message("Enter your full name:");
        }
        if(empty($useremail))
        {
                error_message("Enter your email address!");
                if(empty($userprofile))
                {
                        $userprofile="No comment";
                }
                if($userpassword!=$userpassword2)
                {
                        error_message("your desired password and retyped password mismatch!");
                }
                $link_id=db_connect($default_dbname);
                if(in_use($userid))
                {
                        error_message("userid is in use.Please choose a different ID");
                        $query="INSERT INTO user VALUES(NULL,'$userid',password('$userpassword')'$username','$userposition','$useremail','$userprofile')";
                        $result=mysql_query($query);
                        if($result)
                        {
                                error_message(sql_error());
                        }
                        $usernumber=mysql_insert_id($link_id);
                        html_header(sql_error());
                }
	}
} 
?>
and see what you get next.

Regards,

re:user create

Posted: Sat Sep 29, 2007 6:47 am
by z0
Hello
Yes,I did!!!
I replaced that function with that code & then ran the whole program.
But I am still getting the error :roll:

Posted: Sat Sep 29, 2007 6:51 am
by Hemlata
OK. Post your complete code again, may be somewhere else you have missed closings..
Regards,

Posted: Sat Sep 29, 2007 1:03 pm
by John Cartwright
As they say, not to be a storm on a hot day.. but..

You've already been told exactly what the issue is, and how to fix it.

Your first step is to format your code properly so you can see bracket mismatches, then you should be able to identify the errors in your code.