PDA

View Full Version : I've got myself confused with sessions again!


nanny
05-04-2008, 01:53 AM
Hi I have got a page of email lists that I am dynamically producing onto the page from database.
Now it has email address not showing I have this:

President to <a href="<?php echo $row['emailname']; ?>">email the President click here </a>


Now should the 'emailname' be the primary key instead of the 'contactid' considering I am trying to use the 'emailname' for the link to the next page (I haven't put that page in if you noticed)?
If this is not being posted in a form can a session still work?
I am wanting to go to the email page and whichever the person selects will use a if - else using the 'emailname' for the $to = $row['email'] - the actual email address that corresponds to the 'emailname'.
Does this need a session or can I do without one.
I am confusing myself !!!
I can do this using one email address but to get to one email form and get the correct email address to send it to via the selection from the previous page the use has clicked - brain malfunction on my part.........

pete
05-05-2008, 09:27 PM
I'm not entirely clear from your post what you are wanting to do and without seeing your tables it is difficult to give 100% accurate advice.

It is worth noting you should never display any email on any web page, so for your list of email links I would have something like:

<a href="emailform.php?id=1">Email John Smith</a>
<a href="emailform.php?id=2">Email Jane Doe</a>
<a href="emailform.php?id=3">Email Mr Green</a>

Then on your emailform.php page run a query something like:


if(isset($_GET['id']) && ctype_digit($_GET['id'])){
$db = $db->query(sprintf("SELECT email FROM contacts WERE contact_id = %d LIMIT 1",$_GET['id']));
if($db->getRowCount()==1){
// email script here
$row->email; // that is the email address


} else {
echo 'invalid contact, nice try';
}
} else {
echo 'Please include a valid id';
}
I don't see the need for using sessions. You need to read the PHP manual, look at the mysql functions or better still buy a decent book like MySQL by Paul DuBois and then a good PHP book of, get a beginners one.