php question/help

- English -

Resident Freddy
Joined
Apr 7, 2004
Messages
5,263
The following is a piece of code from my website which I am in the process of doing. I am reading from a database and I want to link to reference the subject ID for example when i click on the home page it will display "http://website/content.php?subj=1".

I have lost myself in trying loads of different ways and Ive come to the conclusion that you cannot do this under a href tag, as it doesnt allow php tags above it.

Code:
<li><a href="content.php?subj=['id']>  //or something similar
	
<?php 
	$result = mysql_query("   //query gets read into result variable
	SELECT * FROM subjects   //subjects is DB table
	WHERE id = 1 //ID is primary key
	", $connection); //ignore the connection thingy 

	confirm_query($result);  //validation to check if query is valid

	while ($row = mysql_fetch_array($result)) { //loop for the print array command
	echo $row ["menu_name"];
}
?> 

</a></li>

Any pointers in the right direction please?:p
 

- English -

Resident Freddy
Joined
Apr 7, 2004
Messages
5,263
Anyone know a simple statement to check if a session is in use?

<li><a href="logout.php">Logout <?php echo $_SESSION['username'] ?></a></li>

It shows Logout username (username being the persons username) ... however when logged out, it nolonger keeps the session username thus throwing a php error. Rather than just stating Logout again. This messes the layout etc/

Thanks
 

ST^

Can't get enough of FH
Joined
Dec 22, 2003
Messages
2,351
You should store a session var such as $_SESSION['logged_in'], and when someone logs in, set it to 1 / true. Then whenever you want to check if the visitor is logged in, ask if $_SESSION['logged_in'] == 1
 

Amanita

Part of the furniture
Joined
Dec 23, 2003
Messages
2,209
Code:
if(isset($_SESSION['username']))
{
  //stuff
}
 

Users who are viewing this thread

Top Bottom