...

View Full Version : Need to pass userid from url to php



gax
08-01-2008, 04:49 PM
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;&nbsp;&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/>";
}
?>

ptmuldoon
08-01-2008, 06:34 PM
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.

gax
08-01-2008, 06:56 PM
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

djm0219
08-01-2008, 07:03 PM
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.

gax
08-01-2008, 07:44 PM
first i tried:


<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.


<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

BWiz
08-01-2008, 08:02 PM
Is your server actually parsing any php code at all? Try just printing something.

ptmuldoon
08-01-2008, 08:05 PM
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).



<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
//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($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/>";
}
?>

gax
08-01-2008, 09:34 PM
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.

gax
08-01-2008, 10:34 PM
so it doesn't work. It just opens up the .php file in notepad, while my original script works. any other ideas?

ptmuldoon
08-01-2008, 10:51 PM
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



$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.

gax
08-01-2008, 11:06 PM
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?

gax
08-04-2008, 03:25 PM
bump this

gax
08-06-2008, 05:46 PM
please any help would be great! thanks



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum