Jump to content

Array w/ Numeric Value Is Ignored


phpretard

Recommended Posts

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'];

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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

)

 

Link to comment
Share on other sites

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';
?>

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.