Problem displaying $_POST data with session
I have a form which collects user info including name, location, url, email address etc etc AND company logo AND appropriate catagories they wish to be associated with (using a checkbox array in $_POST).
I then display a preview of the page (using $_SESSION and hidden form fields to hold the $_POST data) which their data will appear on BEFORE storing it in MySQL with an 'approve' button which links to the PHP page which has the MySQL INSERT query.
The problem i'm having is the preview page in between entry and submission to the database is having trouble with the logo input and the checkbox array input:
$_SESSION['clogo'] = $_POST['clogo'];
$_SESSION['cat[]'] = $_POST['cat[]'];
I get an 'undefined index' error when i try to preview these, however all other standard input is fine, and is then 开发者_StackOverflowpassed along to the insert mysql query on user approval. In addition, if i skip the 'preview page' and go straight to the insert PHP file from the original form, there is no problem, and all data is entered into the database correctly.
Can anyone help
You don't want this:
$_SESSION['cat[]'] = $_POST['cat[]'];
But this:
$_SESSION['cat'] = $_POST['cat'];
I.e., 'cat' is the index of the _POST array, and the element that it refers to is another array.
I'm guessing $_POST['cat']
is an array in itself. (I'm guessing this because of the []
following cat
in your example.) If this is the case, then in your example, you're setting $_SESSION['cat[]']
equal to a variable name that doesn't exist. Try setting $_SESSION['cat']
equal to $_POST['cat']
.
Remember to start the session using the start_session
function. Otherwise nothing will be saved in the session.
Also worth noting is that when using some third party application they might remove all session variables. Wordpress is a good example.
$_POST[] array must be re-initialize, as you are posting to preview page and then php insert script page... When you go directly from form to php script page ,POST have variables in it, so it must be working fine.
'cat[]' would not be the index. The index would be 'cat' which should be an array.
精彩评论