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?