Page 1 of 1

problem with $_GET

Posted: Mon Jun 30, 2008 5:10 pm
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

Re: problem with $_GET

Posted: Mon Jun 30, 2008 5:46 pm
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

Re: problem with $_GET

Posted: Mon Jun 30, 2008 6:37 pm
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']).

Re: problem with $_GET

Posted: Mon Jun 30, 2008 6:53 pm
by Stryks
JAB Creations wrote:You can't $_GET and $_POST simultaneously.
Well there you go. Never tried it ... but now I know. 8)

Re: problem with $_GET

Posted: Mon Jun 30, 2008 6:53 pm
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.

Re: problem with $_GET

Posted: Mon Jun 30, 2008 7:02 pm
by Stryks
Knowledge deleted.

:lol:

Re: problem with $_GET

Posted: Mon Jun 30, 2008 8:16 pm
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:

Re: problem with $_GET

Posted: Mon Jun 30, 2008 9:30 pm
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.

Re: problem with $_GET

Posted: Mon Jun 30, 2008 9:38 pm
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">
 

Re: problem with $_GET

Posted: Mon Jun 30, 2008 9:44 pm
by JAB Creations
Well err...yeah...ok. :mrgreen:

Re: problem with $_GET

Posted: Mon Jun 30, 2008 10:28 pm
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.

Re: problem with $_GET

Posted: Tue Jul 01, 2008 4:49 am
by Eran
Not from the same form, but a request can contain both as I've showed

Re: problem with $_GET

Posted: Tue Jul 01, 2008 4:56 am
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.