Page 1 of 1

Newbie problem

Posted: Thu Dec 30, 2004 11:49 am
by szac
hello,

I am trying to piece together my first script and I am getting an error. I think that I may have my function braces out of whack. anybody have any suggestions?

Code: Select all

<?php

session_start();

$loggedIn = $_SESSION['loggedIn'];
$username = $_SESSION['username'];

if ( $loggedIn != true )
{
die('Verification failed! You must be logged in to view this page.');
}

?>

<p>Welcome to the page <?php echo $username ?>!</p>

<p><a href="logout.php">Logout</a></p>
this works fine until i add

Code: Select all

<?php		
if(file_exists("./proofs/".$username.".gif")){ ?>
		<TABLE>
			<TR>
				<TD colspan="2" CLASS="articlehead">Please review proof and click approve/disapprove once you have made your decision.  More help <a href="../help" >here</a></TD>
			</TR> 
			<TR>
			
				<TD><img src="<?php echo $image; ?>"></TD>
				
				<TD><form action="./proofs/handler.php">
				<input type="radio" name="approve" value="1">Approve<br>
				<input type="radio" name="approve" value="0">Disapprove<br>
				<textarea name="comments" cols="12">Please enter any comments here...</textarea><br>
				<input type="hidden" name="username" value="<?php echo $username; ?>">
				<input type="submit" value="Send notice">
				</form></TD>
			</TR>
		</TABLE>
		<?php
		}
		else { ?>
			
			<TABLE>
			<TR><TD>There aren't any proofs available to view at this time. Please contact us if you think this is a mistake.</TD></TR>
			
			</TABLE>
which is when something to the effect of

Parse error: parse error, unexpected $ in /home/jssilk/public_html/login/user.php on line 49

prints.

thanks for any help.

Posted: Thu Dec 30, 2004 12:14 pm
by ProfMoriarty
It looks like you have a variable being declared or modified in a syntactically incorrect manner. It's not guaranteed to be on the 49th line, but I'd look around there. Good luck.

Posted: Thu Dec 30, 2004 12:25 pm
by szac
Hello,

thanks for the reply. I did some digging and am not having any luck. that error comes from whichever is the last line in the fle.

Posted: Thu Dec 30, 2004 12:30 pm
by andre_c
on the second part of the code you have an ELSE statement without its ending bracket: }

Posted: Thu Dec 30, 2004 1:07 pm
by szac
Thanks! Script is actually working!

Posted: Thu Dec 30, 2004 3:31 pm
by szac
well I got it working by removing the function. when I add it back to the script it prints nothing within the function, not even the last else statement.
here's what I got: I basically just want it to check into a directory for a username gif or jpeg call it $image and print away...

Code: Select all

<?php

session_start();

$loggedIn = $_SESSION['loggedIn'];
$username = $_SESSION['username'];

if ( $loggedIn != true )
{
die('Verification failed! You must be logged in to view this page.');
}

?>

<p>Welcome to the page <?php echo $username ?>!</p>

<p><a href="logout.php">Logout</a></p>

	

<?php 
	
	function userimage($username, $imagespath) { 
		
		$exists = false;
		
		if(file_exists("../proofs/".$username.".gif")) {
			$exists = true;
			$image = "../proofs/".$username.".gif";
		}
		else if(file_exists("../proofs/".$username.".jpg")) {
			$exists = true;
			$image = "../proofs/".$username.".jpg";
		}
		
		if($exists = true) {
		?>

		<TABLE>
			<TR>
				<TD colspan="2" CLASS="articlehead">Please review proof and click approve/disapprove once you have made your decision.  More help <a href="../help" >here</a></TD>
			</TR> 
			<TR>
			
				<TD><img src="<?php echo("../proofs/".$username.".jpg")?>"></TD>
				
				<TD><form action="../proofs/handler.php">
				<input type="radio" name="approve" value="1">Approve<br>
				<input type="radio" name="approve" value="0">Disapprove<br>
				<textarea name="comments" cols="12">Please enter any comments here...</textarea><br>
				<input type="hidden" name="username" value="<?php echo $username; ?>">
				<input type="submit" value="Send notice">
				</form></TD>
			</TR>
		</TABLE>
		<?php
		}
		else { ?>
			
			<TABLE>
			<TR><TD>There aren't any proofs available to view at this time. Please contact us if you think this is a mistake.</TD></TR>
			
			</TABLE><?php }
			}
?>
thanks for any help

Posted: Thu Dec 30, 2004 4:09 pm
by feyd
szac, please read my signature.

Posted: Thu Dec 30, 2004 4:29 pm
by szac
my bad... :oops:

Posted: Thu Dec 30, 2004 4:34 pm
by feyd
everybody (well... 99.9999999% of people) make that mistake in the first few posts here...

some continue to make the mistake for a lot more posts.. they eventually catch on.. :)

Posted: Thu Dec 30, 2004 5:05 pm
by Robert Plank
Ok well first of all:

Code: Select all

if($exists = true) {
Should be:

Code: Select all

if($exists === TRUE) {
The way you have it with one equals sign, $exists will be set to true instead of its value being checked to be true and code inside the else block will never be executed. :)

Posted: Fri Dec 31, 2004 6:03 am
by tomtomtom
The function won't execute at all unless you call it.