[RESOLVED] Passing a Variable to URL
Hi All,
I want to be able to pass the values of 2 variables in my code (HTML/PHP) to a URL, e.g:
<a href="pool_users.php?ContactID=<?php echo $ContactID;?>&AccountID=<?php echo $AccountID;?>">Pool Users</a>
Below is my code, you will notice that I have:
<a href="contacts_list.html">Login Page</a>
<a href="return_contacts_list.php?AccountID=<?php echo $AccountID;?>">User List</a>
<a href="user_details.php?ContactID=<?php echo $ContactID;?>&AccountID=<?php echo $AccountID;?>">User Details</a>
<a href="escalation_details.php?ContactID=<?php echo $ContactID;?>&AccountID=<?php echo $AccountID;?>">Escalation Details</a>
<a href="pool_users.php?ContactID=<?php echo $ContactID;?>&AccountID=<?php echo $AccountID;?>">Pool Users</a>
both above and below my PHP script, this is a test. ONLY the top one displays.
It doesnt pass the variables as you would expect.
But the bottom one below the PHP script doesnt even display....
Why is that the case??? Im stumped.
Any help would be very much appreciated.
PHP Code:
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Admin</title>
<a href="contacts_list.html">Login Page</a>
<a href="return_contacts_list.php?AccountID=<?php echo $AccountID ; ?> ">User List</a>
<a href="user_details.php?ContactID=<?php echo $ContactID ; ?> &AccountID=<?php echo $AccountID ; ?> ">User Details</a>
<a href="escalation_details.php?ContactID=<?php echo $ContactID ; ?> &AccountID=<?php echo $AccountID ; ?> ">Escalation Details</a>
<a href="pool_users.php?ContactID=<?php echo $ContactID ; ?> &AccountID=<?php echo $AccountID ; ?> ">Pool Users</a>
<?php
$_ContactID = $_REQUEST [ "ContactID" ];
$_AccountID = $_REQUEST [ "AccountID" ];
$_Esc1Name = $_REQUEST [ "Esc1Name" ];
$_Esc1Position = $_REQUEST [ "Esc1Position" ];
$_Esc1Phone1 = $_REQUEST [ "Esc1Phone1" ];
$_Esc1Phone2 = $_REQUEST [ "Esc1Phone2" ];
$_Esc1Notes = $_REQUEST [ "Esc1Notes" ];
$link = mysql_connect ( "localhost" , "user" , "password" ) or die( mysql_error ());
if (! $link ) {
die( 'Could not connect: ' . mysql_error ());
}
mysql_select_db ( "peoplesafe" ) or die( mysql_error ());
$sql = "UPDATE contacts SET
Esc1Name=' $_Esc1Name ',
Esc1Position=' $_Esc1Position ',
Esc1Phone1=' $_Esc1Phone1 ',
Esc1Phone2=' $_Esc1Phone2 ',
Esc1Notes=' $_Esc1Notes ',
ModifiedBy='USER'
WHERE ContactID=' $_ContactID ' and AccountID=' $_AccountID '" ;
$query = mysql_query ( $sql );
if ( $query ) {
echo $_AccountID ;
echo $_ContactID ;
exit;
}
mysql_close ();
?>
<a href="contacts_list.html">Login Page</a>
<a href="return_contacts_list.php?AccountID=<?php echo $AccountID ; ?> ">User List</a>
<a href="user_details.php?ContactID=<?php echo $ContactID ; ?> &AccountID=<?php echo $AccountID ; ?> ">User Details</a>
<a href="escalation_details.php?ContactID=<?php echo $ContactID ; ?> &AccountID=<?php echo $AccountID ; ?> ">Escalation Details</a>
<a href="pool_users.php?ContactID=<?php echo $ContactID ; ?> &AccountID=<?php echo $AccountID ; ?> ">Pool Users</a>
</body>
</html>
First problem I see is that your HTML markup is far from valid .
Second problem I see is that you first attempt to use variables before you've ever defined them.
Finally, you haven't shown us what the output of the above PHP code is.
Hi bradgrafelman,
Yip, as i said above, i have tried to use it first, just to show that it actually outputs something, as when i put it after i define the variables it doesnt display anything. Anyway i tried a different approach and it worked. See below, thanks:
PHP Code:
$url_user_list = "return_contacts_list.php?username=" . $_Account . "&password=" . $_AccountID ;
$url_user = "user_details.php?ContactID=" . $_ContactID . "&AccountID=" . $_AccountID ;
$url_esc = "escalation_details.php?ContactID=" . $_ContactID . "&AccountID=" . $_AccountID ;
$url_pool = "pool_users.php?ContactID=" . $_ContactID . "&AccountID=" . $_AccountID ;
echo "<center><table width=55%, border=0>" ;
echo "<td width=25%><center><a href=' $url_user_list '>User List</a></td>" ;
echo "<td width=25%><center><a href=' $url_user '>User Details</a></td>" ;
echo "<td width=25%><center><a href=' $url_esc '>Escalation Details</a></td>" ;
echo "<td width=25%><center><a href=' $url_pool '>Pool Users</a></td></tr>" ;
echo "</table>" ;
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Posting Permissions
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Rules
Bookmarks