Jump to content

checking empty session variables


NickG21

Recommended Posts

hey everyone,
i have multiple form pages that are storing all of the variables using

[code]<?php session_start(); foreach($_POST as $key => $var) { $_SESSION[$key] = $var; } ?>[/code]

I was wondering if anyone could give me an idea of a Loop that could go through these variables as soon as the "next" or "submit" buttons are pressed and just check to make sure none of them are empty?
Link to comment
Share on other sites

well surely you could do this on the page they are sent to so:


[code]
If ($_POST['whatever']='' or $_POST['whatever']='' or $_POST['whatever']'')
{
echo echo '<meta http-equiv=refresh content=0;URL=http://www.YOURSITE.COM/YOURPAGE.php?error=some or all fields were left blank>';
}

[/code]
Link to comment
Share on other sites

Warning: Illegal offset type in /home/web/.../headerImage.php on line 4
Warning: Illegal offset type in /home/web/.../headerImage.php on line 4

[code]<?php
session_start();
foreach($_POST as $key => $var){
if(!empty($_SESSION[$var])) $_SESSION[$key] = $var;
else $empty[] = $key;
}
echo $empty;
?>[/code]

that is the code that i put in and that is the error i get.  if anyone knows any tutorials that would allow me to just do error checking and be able to have someone return back to the previous page to fix them that would be great too and i wouldn't waste people's time with these questions i just can't seem to find a good one yet
Link to comment
Share on other sites

This line:
[code]<?php
if(!empty($_SESSION[$var])) $_SESSION[$key] = $var;
?>[/code]
should read
[code]<?php
if(!empty($var)) $_SESSION[$key] = $var;
?>[/code]

And if you just say "echo $empty", you will get a line saying "Array", use:
[code]<?php
echo '<pre>' . print_r($empty,true) . '</pre>';
?>[/code]

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.