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 :/

 

Link to comment
Share on other sites

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.  :-\

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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.