phpretard Posted April 18, 2008 Share Posted April 18, 2008 If I put letters in the input field it shows up. If I put numbers nothing show up. What am I missing? $file = array(); $file[0] = $_POST['S46']; $file[1] = $_POST['QU46']; // numeric value $file[2] = $_POST['S57']; $file[3] = $_POST['QU57']; // numeric value $file[4] = $_POST['S810']; $file[5] = $_POST['QU810']; // numeric value $file[6] = $_POST['file']; $file[7] = $_POST['picture']; Quote Link to comment Share on other sites More sharing options...
Zhadus Posted April 18, 2008 Share Posted April 18, 2008 What do you see if you do: print_r($file); After you assign those values? Also post form code please. Quote Link to comment Share on other sites More sharing options...
jonsjava Posted April 18, 2008 Share Posted April 18, 2008 I tested the script using this: <?php $_POST['S46'] = "a"; $_POST['QU46'] = "1"; $_POST['S57'] = "b"; $_POST['QU57'] = "2"; $_POST['S810'] = "c"; $_POST['QU810'] = "3"; $_POST['file'] = "test.exe"; $_POST['picture'] = "test.jpg"; $file = array(); $file[0] = $_POST['S46']; $file[1] = $_POST['QU46']; // numeric value $file[2] = $_POST['S57']; $file[3] = $_POST['QU57']; // numeric value $file[4] = $_POST['S810']; $file[5] = $_POST['QU810']; // numeric value $file[6] = $_POST['file']; $file[7] = $_POST['picture']; print_r($file); and I received this as my response: X-Powered-By: PHP/5.2.0 Content-type: text/html Array ( [0] => a [1] => 1 [2] => b [3] => 2 [4] => c [5] => 3 [6] => test.exe [7] => test.jpg ) It appears to be working fine for me Quote Link to comment Share on other sites More sharing options...
phpretard Posted April 18, 2008 Author Share Posted April 18, 2008 This is the array: Array ( [4 x 6] => 4 x 6 [] => [5 x 7] => 5 x 7 [8 x 10] => 8 x 10 [P1040050.jpg] => P1040050.jpg [ALBUMS/Holmes_Adams/P1040050.jpg] => ALBUMS/Holmes_Adams/P1040050.jpg ) Here is the form: <form action=' ' method=post> <input type=hidden name=picture value='$picture'> <input type=hidden name=file value='$file'> <input type=checkbox name=S46 value='4 x 6'> 4 x 6 Quantity:<br> <input type=text name=QU46 size=4> <input type=checkbox name=S57 value='5 x 7'> 5 x 7 Quantity:<br> <input type=text name=QU57 size=4> <input type=checkbox name=S810 value='8 x 10'> 8 x 10 Quantity:<br> <input type=text name=QU810 size=4> <input type=submit name=order_photo value='Order This Photo'> </form> Quote Link to comment Share on other sites More sharing options...
phpretard Posted April 18, 2008 Author Share Posted April 18, 2008 Here is all of the code... if(isset($_POST['order_photo'])) { $file = array(); $file[0] = $_POST['S46']; $file[1] = $_POST['QU46']; $file[2] = $_POST['S57']; $file[3] = $_POST['QU57']; $file[4] = $_POST['S810']; $file[5] = $_POST['QU810']; $file[6] = $_POST['file']; $file[7] = $_POST['picture']; foreach($file as $val){ $_SESSION[$val] = $val; } } Does this make a difference? Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted April 18, 2008 Share Posted April 18, 2008 Can you post all of your code in one post, seeing separate snippets doesn't help. Ken Quote Link to comment Share on other sites More sharing options...
jonsjava Posted April 18, 2008 Share Posted April 18, 2008 <?php if(isset($_POST['order_photo'])) { $_POST['S46'] = "a"; $_POST['QU46'] = "1"; $_POST['S57'] = "b"; $_POST['QU57'] = "2"; $_POST['S810'] = "c"; $_POST['QU810'] = "3"; $_POST['file'] = "test.exe"; $_POST['picture'] = "test.jpg"; $file = array(); $file[0] = $_POST['S46']; $file[1] = $_POST['QU46']; // numeric value $file[2] = $_POST['S57']; $file[3] = $_POST['QU57']; // numeric value $file[4] = $_POST['S810']; $file[5] = $_POST['QU810']; // numeric value $file[6] = $_POST['file']; $file[7] = $_POST['picture']; $val_array = array(); $val_array[] .= "4 x 6"; $val_array[] .= "5 x 7"; $val_array[] .= "8 x 10"; $val_array[] .= "P1040050.jpg"; $val_array[] .= "ALBUMS/Holmes_Adams/P1040050.jpg"; $count = 0; foreach($file as $val){ $_SESSION[$val_array[$count]] = $val; $count++; } } ?> this outputs the following with a print_r: Array ( [4 x 6] => a [5 x 7] => 1 [8 x 10] => b [P1040050.jpg] => 2 [ALBUMS/Holmes_Adams/P1040050.jpg] => c [] => test.jpg ) Quote Link to comment Share on other sites More sharing options...
phpretard Posted April 18, 2008 Author Share Posted April 18, 2008 Do you have anything to say about the code you posted? Quote Link to comment Share on other sites More sharing options...
jonsjava Posted April 18, 2008 Share Posted April 18, 2008 sorry, was working at work while coding that. ok, what it's doing is this: creates an array of session variable names. It also pulls your POST data into the array you had already created. It then takes the posted data array, and places it into a SESSION value (and the session value gets its name from the val_array array). So, if the first value (value "0") for val_array was "cheese" and the first value in the post array (value "0") in the file array was "burger" you would get: <?php $_SESSION['cheese'] = 'burger'; ?> Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted April 18, 2008 Share Posted April 18, 2008 Here is the OP's code (with a few modifications). It seems to work: <?php session_start(); if (isset($_POST['order_photo'])) { echo '<pre>$_POST:' . print_r($_POST,true) . '</pre>'; $file = array(); $file[0] = $_POST['S46']; $file[1] = $_POST['QU46']; $file[2] = $_POST['S57']; $file[3] = $_POST['QU57']; $file[4] = $_POST['S810']; $file[5] = $_POST['QU810']; $file[6] = $_POST['file']; $file[7] = $_POST['picture']; echo '<pre>$file:' . print_r($file,true) . '</pre>'; foreach($file as $val){ $_SESSION[$val] = $val; } echo '<pre>$_SESSION:' . print_r($_SESSION,true) . '</pre>'; } ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <title></title> </head> <body> <form action="" method="post"> <input type="hidden" name=picture value='$picture'> <input type="hidden" name=file value='$file'> <input type="checkbox" name="S46" value='4 x 6'> 4 x 6 Quantity: <input type="text" name="QU46" size=4><br> <input type="checkbox" name="S57" value='5 x 7'> 5 x 7 Quantity: <input type="text" name="QU57" size=4><br> <input type="checkbox" name="S810" value='8 x 10'> 8 x 10 Quantity: <input type="text" name="QU810" size=4><br> <input type="submit" name="order_photo" value='Order This Photo'> </body> </html> Does this code do what you're expecting? Ken Quote Link to comment Share on other sites More sharing options...
phpretard Posted April 18, 2008 Author Share Posted April 18, 2008 You're good... How are the session being named? Quote Link to comment Share on other sites More sharing options...
phpretard Posted April 18, 2008 Author Share Posted April 18, 2008 How can I get the -- $_SESSION:Array-- to exactly match the -- $_POST:Array. Quote Link to comment Share on other sites More sharing options...
phpretard Posted April 18, 2008 Author Share Posted April 18, 2008 This should sum up my problem. http://www.rememberthetimephotos.com/index.php?page=forms/order&picture=ALBUMS/FLM-MINC/P1090702.jpg&BM=P1090702.jpg Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted April 18, 2008 Share Posted April 18, 2008 If you want the $_SESSION array to match the $_POST array: <?php foreach($_POST as $key => $val) $_SESSION[$key] = $val; ?> Ken Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.