problem with $_GET

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
swissbeets
Forum Newbie
Posts: 20
Joined: Thu Jun 26, 2008 7:56 pm

problem with $_GET

Post by swissbeets »

For future reference, please enclose code in your posting, using [ code] and [ /code] tags, as I have done below for you. Thank you.
Moderator


i am trying to add an image source to my database, but it wont let me get the product_id with $_GET with this in my code it doesnt even make it to the data base i will show all code connected

this is the form that takes the information

Code: Select all

<form enctype="multipart/form-data" action="uploader.php?prod=<?php echo urlencode($sel_product['product_id']); ?>" method="POST">
 
<input type="hidden" name="MAX_FILE_SIZE" value="100000" />
 
Choose a file to upload: <input name="uploadedfile" type="file" value= "<?php if(isset($sel_product['image_source'])){echo $sel_product['image_source'];} ?>"/>
 
<input type="submit" value="Upload File" />
 
</form>
after it is sent it goes to this site and i am pretty sure this is where the error is but not positive

Code: Select all

<?php require_once("includes/session.php"); ?>
<?php require_once("includes/connection.php"); ?>
<?php require_once("includes/functions.php"); ?>
<?php confirm_logged_in(); ?>
 
<?php 
 
echo "<pre>";
print_r($_FILES);
echo "</pre>";
 
$target_path = "C:\wamp\www\site\images".$_FILES['uploadedfile']['name'];
 
move_uploaded_file($_FILES['uploadedfile']['tmp_name'],$target_path);
 
$image_source = mysql_prep($target_path);
 
?>
<?php
 
$id = $_GET['prod'];   //<--------- with this it doesnt even make it to the database just displays an array with my values
$query = "INSERT INTO products (
image_source
) VALUES (
'$image_source'
WHERE product_id = {$id})";
                $result = mysql_query($query);
                if (mysql_affected_rows() == 1) {
                    // Success
                    $message = "The product was successfully updated.";
                    redirect_to("edit_product.php");
                } else {
                    // Failed
                    $message = "The product update failed.";
                    $message .= "<br />". mysql_error();
                }?>
 
<!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>
any help is greatly appreciated i feel like i have tried everything
User avatar
Stryks
Forum Regular
Posts: 746
Joined: Wed Jan 14, 2004 5:06 pm

Re: problem with $_GET

Post by Stryks »

I'm a bit confused about the actual problem.
swissbeets wrote:$id = $_GET['prod']; //<--------- with this it doesnt even make it to the database just displays an array with my values
What values? Can we have an example of what it IS returning?

Also, can you add ...

Code: Select all

echo $query;
... just above ...

Code: Select all

$result = mysql_query($query);
... and let us know what it outputs.

Cheers
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

Re: problem with $_GET

Post by JAB Creations »

You can't $_GET and $_POST simultaneously. Try $_POST['prod']. If it's a checkbox and is not checked you need to check for !isset($_POST['prod']).
User avatar
Stryks
Forum Regular
Posts: 746
Joined: Wed Jan 14, 2004 5:06 pm

Re: problem with $_GET

Post by Stryks »

JAB Creations wrote:You can't $_GET and $_POST simultaneously.
Well there you go. Never tried it ... but now I know. 8)
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: problem with $_GET

Post by John Cartwright »

JAB Creations wrote:You can't $_GET and $_POST simultaneously. Try $_POST['prod']. If it's a checkbox and is not checked you need to check for !isset($_POST['prod']).
Yes, you can use $_GET and $_POST simultaneously.
User avatar
Stryks
Forum Regular
Posts: 746
Joined: Wed Jan 14, 2004 5:06 pm

Re: problem with $_GET

Post by Stryks »

Knowledge deleted.

:lol:
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

Re: problem with $_GET

Post by JAB Creations »

Jcart wrote:Yes, you can use $_GET and $_POST simultaneously.
Now you've got me curious Jcart...how is such a thing possible? :mrgreen:
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: problem with $_GET

Post by califdon »

JAB Creations wrote:
Jcart wrote:Yes, you can use $_GET and $_POST simultaneously.
Now you've got me curious Jcart...how is such a thing possible? :mrgreen:
You can use $_REQUEST['xyz']; and it will retrieve both $_GET and $_POST variables, if they exist.

But it's probably a bad habit to get into. You should design your scripts to use one or the other, based on security and other considerations, then write your scripts so that it is clear which you are using. Just for your own sanity.
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: problem with $_GET

Post by Eran »

JAB Creations wrote:
Jcart wrote:Yes, you can use $_GET and $_POST simultaneously.
Now you've got me curious Jcart...how is such a thing possible? :mrgreen:
Simply send a POST request into a GET url

Code: Select all

 
<form method="post" action="form.php?param1=value1&param2=value2">
 
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

Re: problem with $_GET

Post by JAB Creations »

Well err...yeah...ok. :mrgreen:
LBmtb
Forum Newbie
Posts: 23
Joined: Wed May 14, 2008 11:14 am

Re: problem with $_GET

Post by LBmtb »

I think he meant that you can't send form data with both GET and POST. It can only be one or the other on each form.
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: problem with $_GET

Post by Eran »

Not from the same form, but a request can contain both as I've showed
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: problem with $_GET

Post by Benjamin »

Here is how to get and post at the same time:

Code: Select all

 
<form name="test" method="post" action="page_name.php?var1=foo&var2=bar">
  <input type="hidden" name="some_other_var" value="shoe" />
  <input type="submit" value="Post & Get Example" />
</form>
 
EDIT: as pytrin showed above, this is an expanded example.
Post Reply