Jump to content

Isset question


tomfmason

Recommended Posts

I am attempting to create a mysql chat script and am running into a little trouble with the login script.

The problem that I am having is that the errors are being processed before the user has a chance to enter the required information. Here is a relivant section of the script.

[code=php:0]<?php
include('includes/db.php');
if (isset($submit)) {
    array_pop($_POST);
    if ( get_magic_quotes_gpc() ) {
      $_POST= array_map('stripslashes', $_POST);
    }
    $first_name = mysql_real_escape_string(trim($_POST['first_name']));
    $last_name = mysql_real_escape_string(trim($_POST['last_name']));
    $email = mysql_real_escape_string(trim($_POST['email']));
    $status = "waiting";
 
    if ((!$first_name) || (!$last_name) || (!$email) || (!$deparment)) {
        $message = "error";
    if (!$first_name) {
        $error = "first_name";
    }
    if (!last_name) {
        $error = "last_name";
    }
    if (!$email) {
        $error = "email";
    }
    if (!$department) {
        $error = "department";
    }
        exit();
    }

    $sql = mysql_query("INSERT INTO chat (first_name, last_name, email, department, status, chat_date, chat_time)
          VALUES ('$first_name', '$last_name', '$email', '$department', '$status', now(), now())") or die(mysql_error());
 
    if (!$sql) {
    $message = "sql";
    }
    session_start();

    $session_sql = "SELECT chat_id FROM chat WHERE email ='$email' AND status ='waiting'";
    $get_session = mysql_query($session_sql) or die(mysql_error());

    if (!$get_session) {
        $message = "session";
    }
    $_SESSION['chat_id'] = "$get_session";
    header("Location: http://www.owpt.biz/chat.php");
}    
?>[/code]


Should I use


[code=php:0]<?php
if (isset($submit)) {
  if (empty($variable)) {
      $error = "whatever"
  }
  //the rest of my error checking
}[/code]



Any suggestions would be great.
Link to comment
Share on other sites

you should know the different between isset and empty.

case1:
<?php
  $var = null;

  isset($var) will return true here;
  empty($var) will return true here;
?>

case 2:
<?php
  isset($var) will return false here;
  empty($var) will return true here;
?>

case 3:
<?php
  $var = 'something';

  isset($var) will return true here;
  empty($var) will return false here;
?>
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.