MYSQL PHP yazma değişken 0 eşit olur

0 Cevap php

Değişken 0'a eşit ise benim veritabanına yazmaya çalışıyorum. Sorun değişkenler 1 eşittir bile hala veritabanına yazıyor olmasıdır. Yanlış nedir?

echo $new_user;

if ($new_user == 0) {

  //SENT NEW USER WELCOME MESSAGE

  $adminid = '9';
  $welcomemessagetitle = 'Welcome to The site';
  $welcomemessagecontent = 'Hello and welcome';

  $addmessages = "INSERT into `user_messages`(`to_user`,`from_user`,`title`,`content`)
    VALUES ('$userid','$adminid','$welcomemessagetitle','$welcomemessagecontent');";

  $query = mysql_query($addmessages) or die(mysql_error());

  //SET USER AS NOT NEW USER

  $newuservalue = '1';

  $notnewuser = "UPDATE users SET new_user = $newuservalue WHERE id = $userid" ;

  $query2 = mysql_query($notnewuser) or die(mysql_error());

} elseif ($new_user == 1) {};

UPDATE FULL CODE::

<?php 
session_start();
include "../includes/db_connect.php";
///profile/index.php
if($_SESSION['id'])
{
  $username = $_SESSION['username'];
  $userid = $_SESSION['id'];
  //WRITE FIRST TIME LOGIN INFORMATION TO DATABASE
  $sql="SELECT new_user from `users` WHERE `id`= $userid ";
  $res=mysql_query($sql) or die(mysql_error());
  while($row=mysql_fetch_assoc($res)) $new_user = $row['new_user'] ;
  echo $new_user;
  if ($new_user == 0) {
    //SENT NEW USER WELCOME MESSAGE
    $adminid = '9';
    $welcomemessagetitle = 'Welcome to Escorvee';
    $welcomemessagecontent = 'Hello and welcome';
    $addmessages = "INSERT into `user_messages`(`to_user`,`from_user`,`title`,`content`)
      VALUES ('$userid','$adminid','$welcomemessagetitle','$welcomemessagecontent');";

     $query = mysql_query($addmessages) or die(mysql_error());
    //SET USER AS NOT NEW USER
    $newuservalue = '1';
    $notnewuser = "UPDATE users SET new_user = $newuservalue WHERE id = $userid" ;
    $query2 = mysql_query($notnewuser) or die(mysql_error());
  } elseif ($new_user == 1) {};
}
?>

0 Cevap