mark103 Posted March 6, 2012 Share Posted March 6, 2012 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? Quote Link to comment https://forums.phpfreaks.com/topic/258402-how-to-get-pass-on-the-if-variables/ Share on other sites More sharing options...
mark103 Posted March 6, 2012 Author Share Posted March 6, 2012 please can someone help????????? Quote Link to comment https://forums.phpfreaks.com/topic/258402-how-to-get-pass-on-the-if-variables/#findComment-1324606 Share on other sites More sharing options...
ManiacDan Posted March 6, 2012 Share Posted March 6, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/258402-how-to-get-pass-on-the-if-variables/#findComment-1324610 Share on other sites More sharing options...
mark103 Posted March 6, 2012 Author Share Posted March 6, 2012 yes i have tried it and i couldn't find the solution. Any idea? Quote Link to comment https://forums.phpfreaks.com/topic/258402-how-to-get-pass-on-the-if-variables/#findComment-1324617 Share on other sites More sharing options...
Pikachu2000 Posted March 6, 2012 Share Posted March 6, 2012 WHAT did you do to debug this? Post the code you used to try to debug it, and the results, including any error messages. Quote Link to comment https://forums.phpfreaks.com/topic/258402-how-to-get-pass-on-the-if-variables/#findComment-1324619 Share on other sites More sharing options...
mark103 Posted March 6, 2012 Author Share Posted March 6, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/258402-how-to-get-pass-on-the-if-variables/#findComment-1324626 Share on other sites More sharing options...
Pikachu2000 Posted March 6, 2012 Share Posted March 6, 2012 Again, what have you done to debug the problem on your own? Quote Link to comment https://forums.phpfreaks.com/topic/258402-how-to-get-pass-on-the-if-variables/#findComment-1324628 Share on other sites More sharing options...
mark103 Posted March 6, 2012 Author Share Posted March 6, 2012 sorry but i am not sure what you mean by debug the problem and how do you mean it? Quote Link to comment https://forums.phpfreaks.com/topic/258402-how-to-get-pass-on-the-if-variables/#findComment-1324630 Share on other sites More sharing options...
mark103 Posted March 7, 2012 Author Share Posted March 7, 2012 i am not sure what you mean by debug the problem and how do you mean it? Quote Link to comment https://forums.phpfreaks.com/topic/258402-how-to-get-pass-on-the-if-variables/#findComment-1324687 Share on other sites More sharing options...
ManiacDan Posted March 7, 2012 Share Posted March 7, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/258402-how-to-get-pass-on-the-if-variables/#findComment-1324729 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.