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
https://forums.phpfreaks.com/topic/33005-checking-empty-session-variables/
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]
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
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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.