php variable in url

Associate
Joined
30 Nov 2003
Posts
1,614
I'm having a strange problem where by I can print out the contents of my variable fine but when I use this variable in the url its just blank. :confused:

Here's the bits of code that gets the variable

PHP:
	$bandid = $_GET["bandid"];
	print $bandid; //prints out the id just fine

And here's the bit that constructs the url.

PHP:
<a href="image_upload.php?bandid="$bandid"">Upload Image</a>

I've tried fiddling with this all night and I can't for the life of me get it to work.
 
Here's the full code if needed.

user page:

PHP:
<?php 
session_start();
include_once  'functions.php'; //This includes some common functions
	$bandid = $_GET["bandid"];
	print $bandid;
?>
<!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">
<head>
<link href="css/label.css" rel="stylesheet" type="text/css" />
 <title>Label</title>
 <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
 </head>
 <body>
 <div id="container">
<div id="top">
<h1>Graphics Here </h1>
</div>
<div id="control"> <a href="index.php">Home</a> <a href="directory.php">Directory</a> <a href="stats.php">Stats</a> <a href="contact.php">Contact</a> <a href="about.php">About</a> </div>
<div id="leftnav">
<?php
showLogin(); //This is a function in 'functions.php'
?>
  <br />
</div>
<div id="rightnav">
  <h1><br />
    <br />
    <br />
    <br />
    <br />
    <br />
  </h1>
</div>
<div id="content">
  <h1>User Control Panel<br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
      <br />
        <br />
        <br />
      <br />
  </h1>
</div>
<div id="footer"> 
</div>
</div>
</body>
</html>

Function page that contains showLogin() function called.
PHP:
<?php
   function showLogin()
   { 
	  // Check if we have established an authenticated session
     if (isset($_SESSION["authenticatedUser"]))
     {
       $_SESSION["message"] = "You are logged in as ". $_SESSION['authenticatedUser'];
	   echo '<h2><a href="update_details.php">Update details</a><br />
	   		<a "href=image_upload.php?bandid=$bandid">Upload Image</a><br />
        <a href="logout.php">Logout</a></h2>'; 
     }
    else
     {
	  	echo '<h1>Login</h1>
      	<form name="form1" id="form1" method="post" action="loginaction.php">
      	<h2>Username:
     	<input name="loginUser" type="text" id="loginUser" size="8" />
       	<br />
       	Password:
       	<input name="loginPass" type="password" id="loginPass" size="8"/>
      	<br />
      	<input type="submit" name="Submit" value="Go!" class="button"/>
        </h2>
      	</form>
      	<h2><a href="register_details.php">Register</a><br />
		<a href="recoverpass.php">Forgotten password?</a></h2>';
     }
	 echo "<h2>". $_SESSION["message"]. "</h2>";
	} //End showLogin
?>
 
Code:
 <a href="image_upload.php?bandid="$bandid"">Upload Image</a>
change:
Code:
 <a href="image_upload.php?bandid=$bandid">Upload Image</a>
 
Ensure you're safely escaping that GET variable before printing out to the page. Such as casting it as an int ((int)$bandid), or running htmlspecialchars on it (htmlspecialchars($bandid)).
 
Back
Top Bottom