Jump to content

php mysql: Cannot get hyperlinks to work


bratsmasher

Recommended Posts

Hello:
 
I am having a bit of a problem with hyperlinks. I am creating a database to store and organize documents. What I am trying to do is to pull the location of the document (which only stores the direct file name) out of the database, concatonate it to the folder location and then turn it into a working hyperlink. Whenever I try to do so, I get a
 
Parse error: syntax error, unexpected 'file' (T_STRING), expecting ',' or ';'. This has to be a simple matter of not putting a comma or dash in the right place, however I have been staring at my code for a long time and I cannot seem to figure out where it is. Could someone help me? 
 
 
 

 


//connection to the database
$dbhandle = mysql_connect($hostname, $username, $password)
 or die("Unable to connect to MySQL");
echo "Connected to MySQL<br>";
//select a database to work with
$selected = mysql_select_db("$database",$dbhandle)
  or die("Could not select database crfh_db");
echo "connected to DATABASE <br>";

//queries the database tables. Takes data from two tables, staff and pic and joins them together (innerjoin)
$query = "SELECT staff.tfid, staff.lname, staff.fname, pic.file ".
 "FROM staff, pic ".
 "WHERE staff.tfid = pic.tfid and staff.lname='$lname'";
 
$data = mysql_query($query) or die(mysql_error()); 
 
while($info = mysql_fetch_array( $data ))
 {
 
 // Print out the contents of each row into an array
//*********************************************************** 
 Echo '<a href="C:\php\website\files\'.$info['file'].'">Link</a>';
 Echo "<b>Name:</b> ".$info['tfid'] . "<br> ";
 Echo "<b>Email:</b> ".$info['lname'] . " <br>";
 Echo "<b>Phone:</b> ".$info['fname'] . " <tr>";
 
 }
?>


Link to comment
https://forums.phpfreaks.com/topic/276716-php-mysql-cannot-get-hyperlinks-to-work/
Share on other sites

It sort of worked. I recieved a different error this time:

 

Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) on line 34.

 

Does this mean that I still have an error with quotes or am I doing this totally wrong?

Thank you for the help you have given so far. I appreciate it. I tried breaking the code down like you mentioned. I still get that same parse error. Also, I am not sure that I understand what you mean by letting the browser render its own quotes. Does this mean that my code is not written correctly? Is my method incorrect?

 

Btw, I have tested the remaining code and the rest of it works. It is just this single line which I am not understanding.

I have tried it on my server and i'm getting the same error, the browser wasn't rendering it as expected, if you right click of the "Link" and inspect element you will see what i mean. Try setting a new variable above the echo and then try escaping the quotes with backslashes like this:

 

 

$inf = $info['file'];

echo "<a href=\"C:\php\website\files\'.$info['file'].'\">Link</a>";

If it still doesn't work it should at least give you a "Link". We can go from there.

Unfortunately, I am still getting the same error. 

 

"if you right click of the "Link" and inspect element you will see what i mean" - I am not sure what you mean by this. I am not able to get a webpage to generate, so I am not able to right click on a generated link.

 

 

 

//connection to the database
$dbhandle = mysql_connect($hostname, $username, $password) 
 or die("Unable to connect to MySQL");
echo "Connected to MySQL<br>";

//select a database to work with
$selected = mysql_select_db("$database",$dbhandle) 
  or die("Could not select database crfh_db");
echo "connected to DATABASE <br>";


//queries the database tables. Takes data from two tables, staff and pic and joins them together (innerjoin)
$query = "SELECT staff.tfid, staff.lname, staff.fname, pic.file ".
 "FROM staff, pic ".
	"WHERE staff.tfid = pic.tfid and staff.lname='$lname'";
	
$data = mysql_query($query) or die(mysql_error());	
	
while($info = mysql_fetch_array( $data ))
	{
	
	// Print out the contents of each row into an array
//***********************************************************	
$inf = $info['file'];

echo "<a href=\"C:\php\website\files\'.$inf.'\">Link</a>";

	Echo "<b>Name:</b> ".$info['tfid'] . "<br> "; 
	Echo "<b>Email:</b> ".$info['lname'] . " <br>"; 
	Echo "<b>Phone:</b> ".$info['fname'] . " <tr>"; 
	 
	}
?>

Post your exact code and the exact error. Looking at the code you have now:

 

echo "<a href=\"C:\php\website\files\{$inf}\">Link</a>";

 

Should work. It'd be easier to read if you used A. a real url and B. single quotes

but that would work.

Thanks Jessica. my page now generates with links, but the links do not work. Instead of the link that was supposed to generate, I get this:

file:///C:/php/website%0Ciles/%7BCFRH-logo-new.png%7D

This is what I get from right clicking on the link and going to properties. Any ideas as to why the link has become convoluted?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.