HELP needed with if statement


#1

Does anybody have any idea why the following code does not execute correctly. I want the fields in the form to be checked for content on submission but the if condition is just passed even when there isn’t any content held in the fields. I’m confused:

[php]<?php
include ‘initialize.php’;

if (!(isset($_SESSION[‘user_id’])&& $_SESSION[‘user_id’]!=’’))//if the following is false- session not been assigned a valid user value/is blank then…
{
header(‘Location:index.php’);
end();
}
include ‘template/top.php’;
?>

Create Folder

<?php if (isset($_POST['folder_name'], $_POST['folder _description'])) { $folder_name = $_POST['folder_name']; $folder_description = $_POST['folder_description']; if (empty($folder_name) || empty($folder_description)) { echo 'Folder name and description required'; } else { create_folder($folder_name, $folder_description); header('Location: uploads.php'); exit(); } } ?>

Name:

Description:

<?php include 'template/bottom.php'; ?>

[/php]
any help will be much appreciated…thanks


#2

[php]if (!(isset($_SESSION[‘user_id’])&& $_SESSION[‘user_id’]!=’’))//if the following is false- session not been assigned a valid user value/is blank then…
{[/php]

should be

[php]
if (!isset($_SESSION[‘user_id’]) && $_SESSION[‘user_id’]!=’’)//if the following is false- session not been assigned a valid user value/is blank then…
{[/php]
the if condition here will never work because you say “if session user_id isnt set and session user_id isnt empty”…
if session user_id isnt set then you can put the condition AND might use OR

try this:

[php]
if(isset($_SESSION[‘user_id’]))
{

if(empty($_SESSION[‘user_id’]))
{
echo “session set but empty”;
}
else
{
echo “session set and not empty”;
}

}else{
echo “no such session”;
}
[/php]


#3

Still not valid, for the same reasons. Something set it, therefor it can’t be empty. Checking to see if its empty is sufficient validation for what you’re doing.


#4

Thanks but that segment of code works fine. I have another php file that passes the user_id over

Its not that part that I’m having problems with, its either the if statement which check if the $folder_name & $folder_description variables are empty or the if statement checking the isset() of the form $_POST. Can’t work out what it is but it isn’t carrying out the checks correctly.


#5

This - if (isset($_POST[‘folder_name’], $_POST[‘folder _description’])) ?

Its not valid either, should be if (isset($_POST[‘folder_name’]) && isset($_POST[‘folder _description’]))


#6

Sorted it, was the silliest thing, turns out i was looking at all the wrong places. Never included the = symbol when when assigning the form name field:

name'folder_name'

Thanks for everyones help anyway.