Jump to content

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>";
 
 }
?>



Edited by bratsmasher
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?

Edited by bratsmasher

Breaking it down might help.

 

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

What you are doing is letting the browser render its own quotes in the right place after the php has finished. (after the "=" and before the ">").

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.

Edited by Jessica

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?

Edited by bratsmasher
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.