quick question

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
dsjoes
Forum Commoner
Posts: 41
Joined: Thu May 20, 2010 3:15 pm

quick question

Post by dsjoes »

i have got this code:

Code: Select all

// *** Read the value of "Download" (POST or GET method).
if (isset(($_POST['Download'])) $fileName = $_POST['Download'];

if (isset(($_GET['Download'])) $fileName = $_POST['Download'];

// *** Build the link string.
$downloadLink = "<a href=\"$fileName\">Download</a>";
but i not sure what i need to do with it (i did not write it)

i don't know if it goes with my form or the insert script here they are.
this is the form

Code: Select all

<form action="insert.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 insert script

Code: Select all

<?php
$con = mysql_connect("host","user","password");
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: upload_test.php');
mysql_close($con)
?>
User avatar
McInfo
DevNet Resident
Posts: 1532
Joined: Wed Apr 01, 2009 1:31 pm

Re: quick question

Post by McInfo »

Why do you think you need to do something with it if you don't know what to do with it?
dsjoes
Forum Commoner
Posts: 41
Joined: Thu May 20, 2010 3:15 pm

Re: quick question

Post by dsjoes »

i want to use it because when it is working i won't have to put this in everytime

Code: Select all

<a href="test.doc">Download</a>
to link to a new word doc that i have upload on to my site i will be able to just type test.doc and it will create the link in mysql database which is then displayed on the table
dsjoes
Forum Commoner
Posts: 41
Joined: Thu May 20, 2010 3:15 pm

Re: quick question

Post by dsjoes »

anyone?
MartinW
Forum Newbie
Posts: 4
Joined: Mon Dec 20, 2010 6:01 pm

Re: quick question

Post by MartinW »

I suggest putting it after your php script, with echo $downloadLink; after the line where you make the link string, then after the data's put into the database, you can then go directly to your document. Also, where you put this:

Code: Select all

if (isset(($_GET['Download'])) $fileName = $_POST['Download'];
you probably meant this:

Code: Select all

if (isset(($_GET['Download'])) $fileName = $_GET['Download'];
But just out of curiosity, you had two options. Why didn't you just try both of them to see which one does what you want it to do?

Martin
dsjoes
Forum Commoner
Posts: 41
Joined: Thu May 20, 2010 3:15 pm

Re: quick question

Post by dsjoes »

i have tryed it but the download column shows as empty this is what i have done

Code: Select all

<?php
$con = mysql_connect("host","user","password");
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['$downloadLink'] . "</td>";
echo "</tr>";
}
echo "</table>";
if (isset($_POST['Download'])) $fileName = $_POST['Download'];
$downloadLink = "<a href=\"$fileName\">Download1</a>";
mysql_close($con);
?>
Post Reply