Page 1 of 1

$end Problem

Posted: Sun Sep 17, 2006 1:38 am
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]

Posted: Sun Sep 17, 2006 1:40 am
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

Posted: Sun Sep 17, 2006 1:46 am
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]

Posted: Sun Sep 17, 2006 1:48 am
by aaronhall
Read about how to use mysql_fetch_array: http://us3.php.net/mysql_fetch_array

Posted: Sun Sep 17, 2006 7:24 am
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'];

Posted: Fri Sep 22, 2006 1:07 am
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').