Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Apr 2011
    Posts
    76
    Thanks
    0
    Thanked 0 Times in 0 Posts

    PHP FORM SUBMIT with User ID into Database

    Hi guys, need a little help in regards to submitting my form and the id of the user currently logged in needs to display in the FK id of my second table:

    Here is my current code:

    form page:

    PHP Code:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    </head>

    <body>

    <form enctype="multipart/form-data" id="form1" name="form1" method="post" action="secondPic.php">
      <p>
        <label for="name1">Fav Location Name: </label>
      <input type="text" name="name1" id="name1" />
      </p>
      <p>
      <label for="photo1">Fav Location Photo: </label>
     <input type="file" name="photo1"><br> 
      </p>
      <p>
      <label for="id">ID: <? echo $rows['id']; ?> </label>
      <input name="id" type="hidden" id="id" value="<? echo $rows['id']; ?>">
      </p>
      <p>
        <input type="submit" name="submit" id="submit" value="Submit" />
      </p>
    </form>



    </body>
    </html>
    uploader page

    PHP Code:
    <?php
    include "common.php";
    $secondid $_GET['id'];
    DBConnect();



    $Link mysql_connect($Host$User$Password);

    //This is the directory where images will be saved 
     
    $target "second/"
     
    $target $target basename$_FILES['photo1']['name']); 


    $favname $_POST["name1"];
    $pic2=($_FILES['photo1']['name']); 
    $id $_POST["$id"];



    $Query ="INSERT into $Table_2 values ('0', '$id', '$favname', '$pic2')";

    if (
    mysql_db_query ($DBName$Query$Link)){
    print (
    "A record was created <br><a href=index.php> return to index </a>\n");

     
    // Connects to your Database 
     //mysql_connect("localhost", "jonathon_admin", "hello123") or die(mysql_error()) ; 
     //mysql_select_db("jonathon_admin1") or die(mysql_error()) ; 
     
     
     //Writes the photo to the server 
     
    if(move_uploaded_file($_FILES['photo1']['tmp_name'], $target)) 
     { 
     
     
    //Tells you if its all ok 
     
    echo "The file "basename$_FILES['uploadedfile']['name']). " has been uploaded, and your information has been added to the directory"
     } 
     else { 
     
     
    //Gives and error if its not 
     
    echo "Sorry, there was a problem uploading your file."
     } 


    } else {

    print (
    " - Your Record was not created");    
    }

    mysql_close($Link);
    ?>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    </head>

    <body>
    </body>
    </html>

  • #2
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,280
    Thanks
    4
    Thanked 83 Times in 82 Posts
    Did you have a question?
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster


  •  

    Posting Permissions

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