Jump to content

Recommended Posts

Hi guys,

 

I have got a problem with the if variable statements. When I insert the text of the image location, the name of the strings and when I did not insert the username, all I get this:

 

image, strings or username are missing
Username or password are missing.

 

 

It should not display with the "Username or password are missing.", only the "image, strings or username are missing".  The area of the code i am working on:

 

    if($image == '' && $strings == '' && $username == '') {
  $errmsg_arr[] = 'image, strings or username are missing';
  $errflag = true;
    } elseif($username  == '' && $password == ''){
  $errmsg_arr[] = 'Username or password are missing.';
  $errflag = true;
    }

 

 

<?php
session_start();
    define('DB_HOST', 'localhost');
    define('DB_USER', 'myusername');
    define('DB_PASSWORD', 'mypassword');
    define('DB_DATABASE', 'mydbname');
       
    $errmsg_arr = array();
    $errflag = false;

    $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
    if(!$link) {
  die('Failed to connect to server: ' . mysql_error());
    }

    $db = mysql_select_db(DB_DATABASE);
    if(!$db) {

die("Unable to select database");
    }

   function clean($var){

return mysql_real_escape_string(strip_tags($var));
    }
    $image = clean($_GET['image']);
    $strings = clean($_GET['strings']);
    $username = clean($_GET['user']);
    $pass = clean($_GET['pass']);
    $delete = clean($_GET['delete']);

    if($image == '' && $strings == '' && $username == '') {
  $errmsg_arr[] = 'image, strings or username are missing';
  $errflag = true;
    } elseif($username  == '' && $password == ''){
  $errmsg_arr[] = 'Username or password are missing.';
  $errflag = true;
    }
    if($errflag) {
  $_SESSION['ERRMSG_ARR'] = $errmsg_arr;
  echo implode('<br />',$errmsg_arr);
   }
   else {
$insert = array();
if(isset($_GET['image'])) {
    $insert[] = 'image = \'' . clean($_GET['image']) . '\'';
}
if(isset($_GET['strings'])) {
    $insert[] = 'strings = \'' . clean($_GET['strings']) . '\'';
}
if(isset($_GET['user'])) {
    $insert[] = 'username = \'' . clean($_GET['user']) .'\'';
}
if(isset($_GET['pass'])) {
    $insert[] = 'pass = \'' . clean($_GET['pass']) . '\'';
}
if(isset($_GET['delete'])) {
    $insert[] = 'delete = \'' . clean($_GET['delete']) . '\'';
}


if (count($insert)>0) {
   $names = implode(',',$insert);

if(isset($image) && ($strings) && ($username)) {
    echo "test";
} elseif($username && $delete == 'all') {

   if ($delete != NULL)
   {
     mysql_query("DELETE FROM user_list WHERE username='$username'");
     $deleted = mysql_affected_rows();
     
     if($deleted > 0) {
        echo("The data are now deleted");
     } else {
        echo("The user's data is empty");
     }
   }else{
     echo("failed");
   } 
   mysql_close($link);
   }
  }
}
?>

 

Do anyone know how i can get pass on those methods if I enter the images, the name of the strings and the username or the or the username with the password?

Link to comment
https://forums.phpfreaks.com/topic/258402-how-to-get-pass-on-the-if-variables/
Share on other sites

Have you done any debugging of this on your own?  Anything at all?  Have you dumped the contents of $_GET?  Have you done a var_dump of any of the variables in the IF statement?  Why do you believe you can dump 100 lines of code on a group of strangers and get your answer?  Work for yourself and it will happen a lot faster.

 

Also, bumping threads is against the rules.

 

Show the work you've done to debug this on your own and then we'll help you continue to debug.

 

 

I am trying to get pass on the if variable that if i do not insert one of those functions with included image, strings or user, i will always keep get this:

 

Username or password are missing.

 

 

It's just a mess up when I insert the functions in the url and I can't get pass on the if username and password variable. This one is where i am working on it.

 

if($image == '' && $strings == '' && $username == '') {
  $errmsg_arr[] = 'image, strings or username are missing';
  $errflag = true;
} elseif($username  == '' && $password == ''){
  $errmsg_arr[] = 'Username or password are missing.';
  $errflag = true;
    }

 

Please read the first post i have already posted on above of what i have already said it and i am not going to say it twice or over again.

 

You have absolutely no idea how to debug a script on your own?  What do you do when there's a problem like this?  Do you just stare at the screen and pray that you'll see it?

 

I've given you the steps you need to take to start debugging.  they were in the list of questions you failed to answer.

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.