Results 1 to 2 of 2

Thread: quick question about forms

  1. #1
    dsjoes Guest

    Question quick question about forms

    i have got a form that lets me send information to mysql database to be displayed on a table.
    this is the form:
    PHP Code:
    <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:
    PHP Code:
    <?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)
    ?>
    i am wanting to make it easier to make a link in the download section so that i am not having to type this in everytime i add a new link.
    PHP Code:
     This
    <a href="test.doc">Download</a>
    in here
    Download
    : <input name="Download" type="text" /> 
    i have been given this code but i am not sure where i need to put it and if there is anything else i need to do with it:
    PHP Code:
    // *** 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>"
    thanks

  2. #2
    Join Date
    Jun 2007
    Posts
    295
    First, the code you were given has a mistake....in the second line, it should say:

    PHP Code:
    if (isset(($_GET['Download'])) $fileName $_GET['Download']; 
    Secondly, is the field "Download" the file location? If it is, the code should assign $downloadLink the correct address. However, since you are using "header('Location: upload_test.php')" to redirect the page after using all the form variables, you will no longer have a 'Download' form field with which to populate, so it would error out. What you would need to do is change the header in your insert script to be:

    PHP Code:
     header('Location: upload_test.php?Download=' $_POST['Download']); 
    then you'd place the php code you were given (with the above updated line) into the upload_test.php page.

Similar Threads

  1. Quick Question!
    By extylerb in forum Web Design, HTML Reference and CSS
    Replies: 1
    Last Post: 16 Jun 2008, 06:10 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •