$end Problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Drezard2
Forum Newbie
Posts: 4
Joined: Sun Sep 17, 2006 1:35 am

$end Problem

Post by Drezard2 »

Weirdan | 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]


Hello, I need some help with this script. 

Heres the error:

[quote]
Parse error: syntax error, unexpected $end in C:\Program Files\xampp\htdocs\profile.php on line 51
[/quote]

Heres the script:

Code: Select all

<html>
<head>
</head>

<body>

<p>
My Profile:
</p>

<?php
if (isset($_COOKIE['user']) && isset($_COOKIE['pass'])) {
include('connect.php');
$user = $_COOKIE['user'];
$pass = $_COOKIE['pass'];
	
$sql = "SELECT * FROM users WHERE user='$user' AND pass='$pass'";
$result = mysql_query($sql);
$count=mysql_num_rows($result);

	if ($count = 1)
	{
	echo "Welcome to your profile, $user";

	$sql = "SELECT name FROM users WHERE user = '$user'";
	$result = mysql_query($sql) or die("Error: ". mysql_error(). " with query ". $sql);
	$row = mysql_fetch_array($result);
	$name = $row['name'];
	$email = $row['email'];
	echo $name,  $email;
    }
	if ($count = 0) {
	?>
	<meta http-equiv="refresh" content="0;url=logout2.php">;
	<?php
	}
}
if (!isset($_COOKIE['user'])) {
	?>
	<meta http-equiv="refresh" content="0;url=logout2.php">;
	}
	<?php
if (!isset($_COOKIE['pass'])) {
	?>
	<meta http-equiv="refresh" content="0;url=logout2.php">;
	<?php
	}
	?>
</body>
</html>
- Cheers, Daniel


Weirdan | 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]
User avatar
aaronhall
DevNet Resident
Posts: 1040
Joined: Tue Aug 13, 2002 5:10 pm
Location: Back in Phoenix, missing the microbrews
Contact:

Post by aaronhall »

Unexpected $end usually means you missed a closing bracket or semi-colon.

Code: Select all

if (!isset($_COOKIE['user'])) {
   ?>
   <meta http-equiv="refresh" content="0;url=logout2.php">;
   }
Here, your closing bracket is outside of the php tags
Drezard2
Forum Newbie
Posts: 4
Joined: Sun Sep 17, 2006 1:35 am

Post by Drezard2 »

Weirdan | 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]


Duh, I cant believe I did that.

I got another problem.

Code: Select all

<html>
<head>
</head>

<body>

<p>
My Profile:
</p>

<?php
if (isset($_COOKIE['user']) && isset($_COOKIE['pass'])) {
include('connect.php');
$user = $_COOKIE['user'];
$pass = $_COOKIE['pass'];
	
$sql = "SELECT * FROM users WHERE user='$user' AND pass='$pass'";
$result = mysql_query($sql);
$count=mysql_num_rows($result);

	if ($count = 1)
	{
	echo "Welcome to your profile, $user";
	echo "<br>";

	$sql = "SELECT * FROM users WHERE user = '$user'";
	$result = mysql_query($sql) or die("Error: ". mysql_error(). " with query ". $sql);
	$row = mysql_fetch_array($result);
	$name = $row['name'];
	
$sql = "SELECT * FROM users WHERE user = '$user'";
	$result = mysql_query($sql) or die("Error: ". mysql_error(). " with query ". $sql);
	$row = mysql_fetch_array($result);	
	$email = $row['email'];
	echo $name;
	echo $email;
    }
	if ($count = 0) {
	?>
	<meta http-equiv="refresh" content="0;url=logout2.php">;
	<?php
	}
}
if (!isset($_COOKIE['user']) || !isset($_COOKIE['pass'])) {
	?>
	<meta http-equiv="refresh" content="0;url=logout2.php">;
	<?php
	}
	?>

</body>
</html>
It doesnt give me the email only the username and name.

Thanks, Daniel


Weirdan | 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]
User avatar
aaronhall
DevNet Resident
Posts: 1040
Joined: Tue Aug 13, 2002 5:10 pm
Location: Back in Phoenix, missing the microbrews
Contact:

Post by aaronhall »

Read about how to use mysql_fetch_array: http://us3.php.net/mysql_fetch_array
Omsis
Forum Newbie
Posts: 5
Joined: Sat Sep 16, 2006 1:39 pm

Post by Omsis »

if u use mysql_fetch_array() then the array $row must be used as $row[1]
or use mysql_fetch_assoc() and then use $row['name'] !

and there is no need to use mysql_query() twice!

Code: Select all

$query = "SELECT * FROM users WHERE user = '".$user."'";
        $result = mysql_query($query) or die("Err");
        $row = mysql_fetch_assoc($result);
        $name = $row['name'];
        $email = $row['email'];
User avatar
aaronhall
DevNet Resident
Posts: 1040
Joined: Tue Aug 13, 2002 5:10 pm
Location: Back in Phoenix, missing the microbrews
Contact:

Post by aaronhall »

Omsis wrote:if u use mysql_fetch_array() then the array $row must be used as $row[1]
or use mysql_fetch_assoc() and then use $row['name'] !
Actually, with mysql_fetch_array, result fields will be available as both $row[1] and $row['name']. mysql_fetch_row will only make numeric keys available in the array ($row[1]), and mysql_fetch_assoc will only make the field names available as keys ($row['name').
Post Reply