dsjoes 0 Report post Posted December 24, 2010 (edited) i have got my table and it works here is the code <?php$con = mysql_connect("host","user","pass");if (!$con){die('Could not connect: ' . mysql_error());}mysql_select_db("b32_5584692_Docs", $con);$result = mysql_query("SELECT * FROM Docs");echo "<table border='1'><tr><th>Name</th><th>Message</th><th>Download</th></tr>";while($row = mysql_fetch_array($result)){echo "<tr>";echo "<td width='150'>" . $row['Name'] . "</td>";echo "<td width='250'>" . $row['Message'] . "</td>";echo "<td width='100'>" . $row['Download'] . "</td>";echo "</tr>";}echo "</table>";mysql_close($con);?> and what i want to do is make the download part of the table a link so that when i insert new data into the sql database i don't have to type something like this everytime <a href="test.doc">Download</a> this is the form to add to the sql database<form action="insert_test.php" method="post">Name: <input type="text" name="Name" /><br />Message: <input type="text" name="Message" /><br />Download: <input name="Download" type="text" /> <br /><input type="submit" value="Submit" /></form> and this is the upload script<?php $con = mysql_connect("host","user","pass");if (!$con) { die('Could not connect: ' . mysql_error()); }mysql_select_db("b32_5584692_Docs", $con);$sql="INSERT INTO Docs(Name, Message, Download)VALUES('$_POST[Name]','$_POST[Message]','$_POST[Download]')";if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); }echo "Record added";header('Location: index.php');mysql_close($con)?> i want to be able to type things link test.doc into the download part of the form and then the table to show the link to the file.Thanks Edited December 24, 2010 by dsjoes (see edit history) Share this post Link to post Share on other sites
dsjoes 0 Report post Posted December 29, 2010 anyone? Share this post Link to post Share on other sites
sonesay 7 Report post Posted December 29, 2010 Hi, First of all what does the $row['Download'] output? If it is just the file name then you will need to build the anchor tag your self. You should know where the file is being uploaded to so build the anchor tag accordingly. while($row = mysql_fetch_array($result)){echo "<tr>";echo "<td width='150'>" . $row['Name'] . "</td>";echo "<td width='250'>" . $row['Message'] . "</td>";echo "<td width='100'>" . $row['Download'] . "</td>";echo "</tr>";}echo "</table>"; Something like ? while($row = mysql_fetch_array($result)){echo "<tr>";echo "<td width='150'>" . $row['Name'] . "</td>";echo "<td width='250'>" . $row['Message'] . "</td>";echo "<td width='100'><a href='PATH_TO_FILE".$row['Download']."'>" . $row['Download'] . "</a></td>";echo "</tr>";}echo "</table>"; Assuming $row['Download'] contains your file name...Good luck 1 dsjoes reacted to this Share this post Link to post Share on other sites
dsjoes 0 Report post Posted December 30, 2010 (edited) Hi, First of all what does the $row['Download'] output? If it is just the file name then you will need to build the anchor tag your self. You should know where the file is being uploaded to so build the anchor tag accordingly. while($row = mysql_fetch_array($result)){echo "<tr>";echo "<td width='150'>" . $row['Name'] . "</td>";echo "<td width='250'>" . $row['Message'] . "</td>";echo "<td width='100'>" . $row['Download'] . "</td>";echo "</tr>";}echo "</table>"; Something like ? while($row = mysql_fetch_array($result)){echo "<tr>";echo "<td width='150'>" . $row['Name'] . "</td>";echo "<td width='250'>" . $row['Message'] . "</td>";echo "<td width='100'><a href='PATH_TO_FILE".$row['Download']."'>" . $row['Download'] . "</a></td>";echo "</tr>";}echo "</table>"; Assuming $row['Download'] contains your file name...Good luck Thank you that worked and i made a small alteration so that it would display the word download instead of the file name.echo "<td width='100'><a href='/docs".$row['Download']."'>Download</a></td>"; how would i be able to do it with this one <td><? echo $rows['Download']; ?></td> i tryed but it dosn't work<td><? echo <a href='/docs"$row['Download']"'>Download</a>; ?></td> Edited December 30, 2010 by dsjoes (see edit history) Share this post Link to post Share on other sites
sonesay 7 Report post Posted December 31, 2010 <td><? echo <a href='/docs"$row['Download']"'>Download</a>; ?></td> Try not to mix standard HTML tags with your echo PHP statement. It makes it more organized and less prone to errors as what ever editor you may be using can highlight the HTML code.This is how I would write it but its really up to personal preference.<td><a href="/docs/<?php echo $row['Download']; ?>">Download</a></td> 1 dsjoes reacted to this Share this post Link to post Share on other sites
dsjoes 0 Report post Posted December 31, 2010 <td><? echo <a href='/docs"$row['Download']"'>Download</a>; ?></td>Try not to mix standard HTML tags with your echo PHP statement. It makes it more organized and less prone to errors as what ever editor you may be using can highlight the HTML code.This is how I would write it but its really up to personal preference.<td><a href="/docs/<?php echo $row['Download']; ?>">Download</a></td> it is not picking up the field name so it is just giving links like example.com/"" Share this post Link to post Share on other sites
sonesay 7 Report post Posted January 1, 2011 it is not picking up the field name so it is just giving links like example.com/"" It's probably because your $row['Download'] is not a table field name (column) or the records just contain an empty string. Verify the field name and records for it in the database.Good luck 1 dsjoes reacted to this Share this post Link to post Share on other sites
dsjoes 0 Report post Posted January 1, 2011 It's probably because your $row['Download'] is not a table field name (column) or the records just contain an empty string. Verify the field name and records for it in the database.Good luck thanks it is working now and i didn't have to change anything and both script you helped me with used the same database table and the first one was still working. Share this post Link to post Share on other sites