Newbie 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
szac
Forum Newbie
Posts: 7
Joined: Thu Dec 30, 2004 11:42 am

Newbie problem

Post 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.
Last edited by szac on Thu Dec 30, 2004 4:30 pm, edited 2 times in total.
ProfMoriarty
Forum Newbie
Posts: 7
Joined: Wed Dec 29, 2004 5:09 pm
Location: Juneau, AK

Post 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.
szac
Forum Newbie
Posts: 7
Joined: Thu Dec 30, 2004 11:42 am

Post 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.
User avatar
andre_c
Forum Contributor
Posts: 412
Joined: Sun Feb 29, 2004 6:49 pm
Location: Salt Lake City, Utah

Post by andre_c »

on the second part of the code you have an ELSE statement without its ending bracket: }
szac
Forum Newbie
Posts: 7
Joined: Thu Dec 30, 2004 11:42 am

Post by szac »

Thanks! Script is actually working!
szac
Forum Newbie
Posts: 7
Joined: Thu Dec 30, 2004 11:42 am

Post 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
Last edited by szac on Thu Dec 30, 2004 4:28 pm, edited 1 time in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

szac, please read my signature.
szac
Forum Newbie
Posts: 7
Joined: Thu Dec 30, 2004 11:42 am

Post by szac »

my bad... :oops:
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.. :)
Robert Plank
Forum Contributor
Posts: 110
Joined: Sun Dec 26, 2004 9:04 pm
Contact:

Post 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. :)
tomtomtom
Forum Newbie
Posts: 8
Joined: Tue Dec 28, 2004 12:39 pm

Post by tomtomtom »

The function won't execute at all unless you call it.
Post Reply