Jump to content

[SOLVED] if }else{ statement not working correctly.


bizerk

Recommended Posts

I have an uploader script in which a person can upload any file, as long as they provide the correct credentials and press submit. If the specific variables = the correct values than the file they uploaded will be copied toa certain directory. Now this is where I am confused. When I say ELSE "Wrong credentials", nothing happens. The WRONG CREDENTIALS text is there on the page before I even submit anything. Here is the code:

 

<form name="form1" method="post" action="" enctype="multipart/form-data">
<b><u>LOGIN INFORMATION:</u></b>
<br />Name: <input type="text" name="name" />

Password: <input type="password" name="password" />
<b><u>Upload a File:</u></b><br />
<input type="file" name="imagefile">
<br>
<input type="submit" name="Submit" value="Submit">
<br /><br /><br />

<?
$lol = rand(1,100);
$name = $_POST['name'];
$password = $_POST['password'];
if(isset( $Submit ) and $name =="example" and $password =="pass123")
{
copy ($_FILES['imagefile']['tmp_name'], "files/$lol".$_FILES['imagefile']['name'])
or die ("Something Went Wrong When Trying To Copy");
    echo "<br>"; 
        echo "Name: ".$_FILES['imagefile']['name']."<br>"; 
        echo "Size: ".$_FILES['imagefile']['size']."<br>"; 
        echo "Type: ".$_FILES['imagefile']['type']."<br>"; 
        echo "File has been copied...."; 

            echo "<br><br>";
            echo "Uploaded Correctly";
		}else{
		echo "Wrong Credentials, Please try Again.";
		}
?>

</form>
</body>
</html>

 

Here are links to what IT LOOKS LIKE when i go to the page(before i press ANYTHING).

 

-http://img69.imageshack.us/my.php?image=picture11jl2.png

 

The rest of the Script works perfectly. I am stumped. Maybe because I am not using a form action? Should i make it go to a uploadproccess.php script where it performs the PHP Code? hmm :/

 

Try using another if tag inside the if(isset) to check the password after the button has been pressed.

 

<?php
//...
if(isset($Submit))
{
if($name != "example" || $password != "pass123")
{
	//Incorrect
	echo "Not right";
	exit;
}
//Will continue from here on if name and password is correct
//...
}
?>

 

There are probably more efficient ways.  :-\

Can you try this:

 

<form name="form1" method="post" action="" enctype="multipart/form-data">
<b><u>LOGIN INFORMATION:</u></b>
<br />Name: <input type="text" name="name" />

Password: <input type="password" name="password" />
<b><u>Upload a File:</u></b><br />
<input type="file" name="imagefile">
<br>
<input type="submit" name="Submit" value="Submit">
<br /><br /><br />

<?
$lol = rand(1,100);
$name = $_POST['name'];
$password = $_POST['password'];
if($_POST['Submit']) {

if($name =="example" and $password =="pass123")
{
copy ($_FILES['imagefile']['tmp_name'], "files/$lol".$_FILES['imagefile']['name'])
or die ("Something Went Wrong When Trying To Copy");
    echo "<br>"; 
        echo "Name: ".$_FILES['imagefile']['name']."<br>"; 
        echo "Size: ".$_FILES['imagefile']['size']."<br>"; 
        echo "Type: ".$_FILES['imagefile']['type']."<br>"; 
        echo "File has been copied...."; 

            echo "<br><br>";
            echo "Uploaded Correctly";
		}else{
		echo "Wrong Credentials, Please try Again.";
		}
}
?>

</form>
</body>

Archived

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

×
×
  • 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.