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
swissbeets
Forum Newbie
Posts: 20 Joined: Thu Jun 26, 2008 7:56 pm
Post
by swissbeets » Mon Jun 30, 2008 5:10 pm
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
Stryks
Forum Regular
Posts: 746 Joined: Wed Jan 14, 2004 5:06 pm
Post
by Stryks » Mon Jun 30, 2008 5:46 pm
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 ...
... just above ...
... and let us know what it outputs.
Cheers
JAB Creations
DevNet Resident
Posts: 2341 Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:
Post
by JAB Creations » Mon Jun 30, 2008 6:37 pm
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']) .
Stryks
Forum Regular
Posts: 746 Joined: Wed Jan 14, 2004 5:06 pm
Post
by Stryks » Mon Jun 30, 2008 6:53 pm
JAB Creations wrote: You can't $_GET and $_POST simultaneously.
Well there you go. Never tried it ... but now I know.
John Cartwright
Site Admin
Posts: 11470 Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:
Post
by John Cartwright » Mon Jun 30, 2008 6:53 pm
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.
Stryks
Forum Regular
Posts: 746 Joined: Wed Jan 14, 2004 5:06 pm
Post
by Stryks » Mon Jun 30, 2008 7:02 pm
Knowledge deleted.
JAB Creations
DevNet Resident
Posts: 2341 Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:
Post
by JAB Creations » Mon Jun 30, 2008 8:16 pm
Jcart wrote: Yes, you can use $_GET and $_POST simultaneously.
Now you've got me curious Jcart...how is such a thing possible?
califdon
Jack of Zircons
Posts: 4484 Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA
Post
by califdon » Mon Jun 30, 2008 9:30 pm
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?
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.
Eran
DevNet Master
Posts: 3549 Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME
Post
by Eran » Mon Jun 30, 2008 9:38 pm
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?
Simply send a POST request into a GET url
Code: Select all
<form method="post" action="form.php?param1=value1¶m2=value2">
JAB Creations
DevNet Resident
Posts: 2341 Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:
Post
by JAB Creations » Mon Jun 30, 2008 9:44 pm
Well err...yeah...ok.
LBmtb
Forum Newbie
Posts: 23 Joined: Wed May 14, 2008 11:14 am
Post
by LBmtb » Mon Jun 30, 2008 10:28 pm
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.
Eran
DevNet Master
Posts: 3549 Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME
Post
by Eran » Tue Jul 01, 2008 4:49 am
Not from the same form, but a request can contain both as I've showed
Benjamin
Site Administrator
Posts: 6935 Joined: Sun May 19, 2002 10:24 pm
Post
by Benjamin » Tue Jul 01, 2008 4:56 am
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.