Jump to content

Archived

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

tomfmason

Isset question

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.

Share this post


Link to post
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;
?>

Share this post


Link to post
Share on other sites

×

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.