Page 1 of 1

quick question

Posted: Fri Dec 17, 2010 5:08 am
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)
?>

Re: quick question

Posted: Fri Dec 17, 2010 4:06 pm
by McInfo
Why do you think you need to do something with it if you don't know what to do with it?

Re: quick question

Posted: Fri Dec 17, 2010 4:35 pm
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

Re: quick question

Posted: Mon Dec 20, 2010 3:00 pm
by dsjoes
anyone?

Re: quick question

Posted: Mon Dec 20, 2010 7:51 pm
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

Re: quick question

Posted: Tue Dec 21, 2010 11:12 am
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);
?>