bratsmasher Posted April 9, 2013 Share Posted April 9, 2013 (edited) 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 April 9, 2013 by bratsmasher Quote Link to comment Share on other sites More sharing options...
xxclear Posted April 9, 2013 Share Posted April 9, 2013 Can you put code quotes around the code so its highlighted, people maybe more inclined to help that all. like this Quote Link to comment Share on other sites More sharing options...
bratsmasher Posted April 9, 2013 Author Share Posted April 9, 2013 how do I do that? Quote Link to comment Share on other sites More sharing options...
xxclear Posted April 9, 2013 Share Posted April 9, 2013 Highlight the code and press the button that looks like "<>" Quote Link to comment Share on other sites More sharing options...
Jessica Posted April 9, 2013 Share Posted April 9, 2013 And include the line number of the error. Quote Link to comment Share on other sites More sharing options...
bratsmasher Posted April 9, 2013 Author Share Posted April 9, 2013 I am getting an error on line 34. Quote Link to comment Share on other sites More sharing options...
xxclear Posted April 9, 2013 Share Posted April 9, 2013 You have single quotes inside single quotes there. Echo "<a href=C:\php\website\files\'.$info['file'].'>Link</a>"; Does that work ^^ Quote Link to comment Share on other sites More sharing options...
bratsmasher Posted April 9, 2013 Author Share Posted April 9, 2013 (edited) 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 April 9, 2013 by bratsmasher Quote Link to comment Share on other sites More sharing options...
xxclear Posted April 9, 2013 Share Posted April 9, 2013 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 ">"). Quote Link to comment Share on other sites More sharing options...
bratsmasher Posted April 9, 2013 Author Share Posted April 9, 2013 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. Quote Link to comment Share on other sites More sharing options...
xxclear Posted April 9, 2013 Share Posted April 9, 2013 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. Quote Link to comment Share on other sites More sharing options...
bratsmasher Posted April 9, 2013 Author Share Posted April 9, 2013 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>"; } ?> Quote Link to comment Share on other sites More sharing options...
Jessica Posted April 9, 2013 Share Posted April 9, 2013 OMFG. echo '<a href="C:\php\website\files\'.$info['file'].'">Link</a>'; Quote Link to comment Share on other sites More sharing options...
bratsmasher Posted April 9, 2013 Author Share Posted April 9, 2013 If it is any help, the format that I have the file names saved are filename.pdf . I am only storing the direct name. Quote Link to comment Share on other sites More sharing options...
xxclear Posted April 9, 2013 Share Posted April 9, 2013 OMFG. echo '<a href="C:\php\website\files\'.$info['file].'">Link</a>'; Doesn't work! We tried that. lol Quote Link to comment Share on other sites More sharing options...
bratsmasher Posted April 9, 2013 Author Share Posted April 9, 2013 Unfortunately, that did not work either. I'm still getting that damn parsing error. Quote Link to comment Share on other sites More sharing options...
xxclear Posted April 9, 2013 Share Posted April 9, 2013 If it is any help, the format that I have the file names saved are filename.pdf . I am only storing the direct name. That file name wont make a difference. Quote Link to comment Share on other sites More sharing options...
Jessica Posted April 9, 2013 Share Posted April 9, 2013 (edited) 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 April 9, 2013 by Jessica Quote Link to comment Share on other sites More sharing options...
bratsmasher Posted April 9, 2013 Author Share Posted April 9, 2013 (edited) 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 April 9, 2013 by bratsmasher Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.