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 13 of 13
  1. #1
    gax
    gax is offline
    New Coder
    Join Date
    Aug 2008
    Posts
    67
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Post Need to pass userid from url to php

    What the program will do:
    This program as of now asks the user to input there userid into box, browse for the file to upload, and then asks for a description. When you click upload it connects to our oracle db, inserts the values into the table, disconnects, and saves it.
    Problem:
    We want the userid to be pulled from the url and passed into the form "add_acq.php" instead of the user inputting there userid into the box.
    So for example:
    http://www.blah.com/?userid="blah"
    It will pull "user" and pass it into the oracle db. So i want to make the userid box disappear so it grabs the userid from the url and passes it. I am running apache 2.2.4 and PHP 5.2.6. Any help would be much appriciated.

    <html>
    <form enctype="multipart/form-data" action="add_acq.php" method="POST">
    <p align="center" style="margin-bottom: 0"><font face="Arial">Enter
    EPS userid:</font></p>
    <p align="center" style="margin-top: 0; margin-bottom: 0"><font face="Arial"><input type="text" name="userid" size="20">
    <br>
    <p align="center"><i><b><font face="Verdana" size="4" color="#003399">
    Engineering Property System - Upload a File</font></b></i></p>
    <br>
    <p align="center">Select a File:</font></p>
    <p align="center" style="margin-top: 0"><font face="Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <input type="file" name="filename" size="20"></font></p>
    <p align="center" style="margin-bottom: 0"><font face="Arial">File Description:</font></p>
    <p align="center" style="margin-top: 0"><font face="Arial">
    <input type="text" name = "descrip" size="20"></font></p>
    <p align="center">
    <input type="submit" value="Upload File"></p>
    </form>
    </html>
    This goes to: add_acq.php
    <?php
    //This is the directory where images will be saved
    $target = "E:/docs/acq08/".$HTTP_POST_FILES['filename']['name'];
    //This gets all the other information from the form
    $userid=$_POST['userid'];
    $descrip=$_POST['descrip'];
    $file=($_FILES['filename']['name']);
    // Connects to the Database
    if ($c=OCILogon("eps_attach", "eps_attach", "epsdev"))
    {
    echo "Successfully connected to EPS.\n <BR/><BR/>";
    }
    else
    {
    $err = OCIError();
    echo "Oracle Connection Error <BR/>" . $err[text];
    }
    //Writes the information to the database
    $s = OCIParse($c, "insert into eps.upload_attach values ('$userid', '$file', '$descrip', sysdate, 'ACQ', null)");
    OCIExecute($s, OCI_DEFAULT);
    //echo "EPS Attachment record created.<BR/>\n";
    OCICommit($c);
    //Writes the file to the server
    if(move_uploaded_file($_FILES['filename']['tmp_name'], $target))
    {
    //Tells you if its all ok
    echo "Your file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded, and your information has been added.<BR/><BR/>Please close this window, and Save the information in EPS.<BR/><BR/>";
    }
    else {
    //Gives an error if it is not
    echo "Sorry, there was a problem uploading your file.<BR/> <BR/> <BR/> <BR/> <BR/> <BR/>";
    }
    ?>
    Last edited by gax; 08-01-2008 at 04:00 PM. Reason: didnt add [code] tag

  • #2
    Regular Coder
    Join Date
    Feb 2005
    Posts
    663
    Thanks
    5
    Thanked 14 Times in 14 Posts
    Just use $_GET

    Example:

    $userid = $_GET['userid'];

    Of course, this means you can upload a file to any id simply by changing the userid in the url.

    You may want to include some kind if check to ensure the logged in user can only upload their own info. You may also want to limit the type of file uploads allowed for additional security.
    Last edited by ptmuldoon; 08-01-2008 at 05:38 PM.

  • #3
    gax
    gax is offline
    New Coder
    Join Date
    Aug 2008
    Posts
    67
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by ptmuldoon View Post
    Just use $_GET

    Example:

    $userid = $_GET['userid'];

    Of course, this means you can upload a file to any id simply by changing the userid in the url.

    You may want to include some kind if check to ensure the logged in user can only upload their own info. You may also want to limit the type of file uploads allowed for additional security.
    I wish it was that simple ive already tried this route and it doesnt work.. any other ideas?
    and if i go this route do i set the form box to hidden? or just put what your saying. please be more detailed

  • #4
    Senior Coder djm0219's Avatar
    Join Date
    Aug 2003
    Location
    Wake Forest, North Carolina
    Posts
    1,303
    Thanks
    4
    Thanked 204 Times in 201 Posts
    Exactly what did you try that didn't work? The more specific and detailed you can be the better we can try to help you.
    Dave .... HostMonster for all of your hosting needs

  • #5
    gax
    gax is offline
    New Coder
    Join Date
    Aug 2008
    Posts
    67
    Thanks
    0
    Thanked 0 Times in 0 Posts
    first i tried:
    Code:
    <input type="text" name="userid" size="20" value="<?php echo $_GET['userid']; ?>">
    <form enctype="multipart/form-data" action="add_acq.php?userid=<?php echo $_GET['userid']; ?>" method="POST">
    and with these i set
    $userid = $_GET['userid'];
    that didnt work
    all that happens is it puts $_GET['userid']; in the userid box
    #2.
    i tried creating a session.
    Code:
    <html>
    <form enctype="multipart/form-data" action="add_acq.php" method="POST">
    <p align="center" style="margin-bottom: 0"><font face="Arial">Enter
    EPS userid:</font></p>
    <p align="center" style="margin-top: 0; margin-bottom: 0"><font face="Arial"><input type="text" name="userid" size="20">
    <br>
    <p align="center"><i><b><font face="Verdana" size="4" color="#003399">
    Engineering Property System - Upload a File</font></b></i></p>
    <br>
    <p align="center">Select a File:</font></p>
    <p align="center" style="margin-top: 0"><font face="Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <input type="file" name="filename" size="20"></font></p>
    <p align="center" style="margin-bottom: 0"><font face="Arial">File Description:</font></p>
    <p align="center" style="margin-top: 0"><font face="Arial">
    <input type="text" name = "descrip" size="20"></font></p>
    <p align="center">
    <input type="submit" value="Upload File"></p>
    </form>
    </html>
    This goes to: add_acq.php
    <?php
    //This is the directory where images will be saved
    $target = "E:/docs/acq08/".$HTTP_POST_FILES['filename']['name'];
    //This gets all the other information from the form
    $userid=$_POST['userid'];
    $descrip=$_POST['descrip'];
    $file=($_FILES['filename']['name']);
    // Connects to the Database
    if ($c=OCILogon("eps_attach", "eps_attach", "epsdev"))
    {
    echo "Successfully connected to EPS.\n <BR/><BR/>";
    }
    else
    {
    $err = OCIError();
    echo "Oracle Connection Error <BR/>" . $err[text];
    }
    //Writes the information to the database
    $s = OCIParse($c, "insert into eps.upload_attach values ('$userid', '$file', '$descrip', sysdate, 'ACQ', null)");
    OCIExecute($s, OCI_DEFAULT);
    //echo "EPS Attachment record created.<BR/>\n";
    OCICommit($c);
    //Writes the file to the server
    if(move_uploaded_file($_FILES['filename']['tmp_name'], $target))
    {
    //Tells you if its all ok
    echo "Your file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded, and your information has been added.<BR/><BR/>Please close this window, and Save the information in EPS.<BR/><BR/>";
    }
    else {
    //Gives an error if it is not
    echo "Sorry, there was a problem uploading your file.<BR/> <BR/> <BR/> <BR/> <BR/> <BR/>";
    }
    ?>
    ive also tweaked #1 a little each time to see if anything with that would work and nothing.
    any of your guys help would be much appriciated
    Last edited by gax; 08-01-2008 at 06:48 PM.

  • #6
    Regular Coder BWiz's Avatar
    Join Date
    Mar 2006
    Location
    Sol System
    Posts
    471
    Thanks
    7
    Thanked 21 Times in 21 Posts
    Is your server actually parsing any php code at all? Try just printing something.
    BWiz :: Happy Coding!
    2006
    2007 2008 2009
    2010 2011
    Irrational numbers make no sense.

  • #7
    Regular Coder
    Join Date
    Feb 2005
    Posts
    663
    Thanks
    5
    Thanked 14 Times in 14 Posts
    A few things to note. I don't recommend using the same variable, $userid twice. It could cause conflicts later for you. Also, use php tags when posting php code. It makes it easier to follow the code.

    Next, think it out logically, first you need to get the variable from the url. Then you need to add it to your form. Something like below (note: untested).

    PHP Code:
    <html>

    <?php
    $userid 
    $_GET['userid'];
    ?>

    <form enctype="multipart/form-data" action="add_acq.php" method="POST">
        <input type="hidden" name="userid" size="20" value="<?php $userid?>" />

        <p align="center"><i><b><font face="Verdana" size="4" color="#003399">Engineering Property System - Upload a File</font></b></i></p>
        <br>
        <p align="center">Select a File:</font></p>
        <p align="center" style="margin-top: 0"><font face="Arial">
        <input type="file" name="filename" size="20"></font></p>
        <p align="center" style="margin-bottom: 0"><font face="Arial">File Description:</font></p>
        <p align="center" style="margin-top: 0"><font face="Arial">
        <input type="text" name = "descrip" size="20"></font></p>
        <p align="center">
        <input type="submit" value="Upload File"></p>
    </form>
    </html>
    This goes to: add_acq.php
    PHP Code:
    <?php
    //This is the directory where images will be saved
    $target "E:/docs/acq08/".$HTTP_POST_FILES['filename']['name'];
    //This gets all the other information from the form
    $user_id $_POST['userid'];
    $descrip $_POST['descrip'];
    $file = ($_FILES['filename']['name']);
    // Connects to the Database
    if ($c=OCILogon("eps_attach""eps_attach""epsdev"))
    {
    echo 
    "Successfully connected to EPS.\n <BR/><BR/>";
    }
    else
    {
    $err OCIError();
    echo 
    "Oracle Connection Error <BR/>" $err[text];
    }
    //Writes the information to the database
    $s OCIParse($c"insert into eps.upload_attach values ('$user_id', '$file', '$descrip', sysdate, 'ACQ', null)");
    OCIExecute($sOCI_DEFAULT);
    //echo "EPS Attachment record created.<BR/>\n";
    OCICommit($c);
    //Writes the file to the server
    if(move_uploaded_file($_FILES['filename']['tmp_name'], $target))
    {
    //Tells you if its all ok
    echo "Your file "basename$_FILES['uploadedfile']['name']). " has been uploaded, and your information has been added.<BR/><BR/>Please close this window, and Save the information in EPS.<BR/><BR/>";
    }
    else {
    //Gives an error if it is not
    echo "Sorry, there was a problem uploading your file.<BR/> <BR/> <BR/> <BR/> <BR/> <BR/>";
    }
    ?>
    Last edited by ptmuldoon; 08-01-2008 at 07:07 PM.

  • #8
    gax
    gax is offline
    New Coder
    Join Date
    Aug 2008
    Posts
    67
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thank you guys for quick replies i really appriciate it. ok in regards to the userid twice, im confused on this? Why would i not use the same name twice because if i change the name how will it know how to pass the variable. keep in mind i am a complete php newbie, i made this program all on my own and still don't understand some aspects. anyways, i will test and post a reply.

  • #9
    gax
    gax is offline
    New Coder
    Join Date
    Aug 2008
    Posts
    67
    Thanks
    0
    Thanked 0 Times in 0 Posts
    so it doesn't work. It just opens up the .php file in notepad, while my original script works. any other ideas?

  • #10
    Regular Coder
    Join Date
    Feb 2005
    Posts
    663
    Thanks
    5
    Thanked 14 Times in 14 Posts
    I think you need to backup and begin learning and coding your script one piece at time. For example, the below will echo/print a userid of 6 when you include it in a url

    PHP Code:
    $userid $_GET['userid'];

    echo 
    $userid
    when you include myfile.php&userid=6. So as you can see the $_GET is passing the value from the url.

    Next you simply need to include that in your form. Start viewing the source when viewing the page to make sure you see the userid value.

    Then you need to pass that value using $_POST to the script that is processing the form.

  • #11
    gax
    gax is offline
    New Coder
    Join Date
    Aug 2008
    Posts
    67
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I understand the php code. But w/o what i want to do right now, my script is working perfect.
    when you include myfile.php&userid=6. So as you can see the $_GET is passing the value from the url.

    Next you simply need to include that in your form. Start viewing the source when viewing the page to make sure you see the userid value.

    Then you need to pass that value using $_POST to the script that is processing the form.
    I dont understand what you are saying here? Question though. Is there anyway in php you can grab windows userid that is logged in and pass that into the oracle table, this is what i was originally trying to do, but this has to been done in asp correct?

  • #12
    gax
    gax is offline
    New Coder
    Join Date
    Aug 2008
    Posts
    67
    Thanks
    0
    Thanked 0 Times in 0 Posts
    bump this

  • #13
    gax
    gax is offline
    New Coder
    Join Date
    Aug 2008
    Posts
    67
    Thanks
    0
    Thanked 0 Times in 0 Posts
    please any help would be great! thanks


  •  

    Posting Permissions

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