bizerk Posted February 15, 2007 Share Posted February 15, 2007 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 :/ Quote Link to comment Share on other sites More sharing options...
JBalius Posted February 15, 2007 Share Posted February 15, 2007 Hi, is $Submit set? I don't see it being set anywhere in the code. Quote Link to comment Share on other sites More sharing options...
JBS103 Posted February 15, 2007 Share Posted February 15, 2007 You are missing the post for $Submit. I don't think anything is assigned to it. Edit - Oops, someone got there before me. Good luck. Quote Link to comment Share on other sites More sharing options...
bizerk Posted February 15, 2007 Author Share Posted February 15, 2007 Even when i set $Submit = $_POST['Submit']; the Else statement still does not function correctly. I tried taking the whole isset( $Submit) line out as well, and that did not change anything. Any other suggestions? Quote Link to comment Share on other sites More sharing options...
JBS103 Posted February 15, 2007 Share Posted February 15, 2007 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. :-\ Quote Link to comment Share on other sites More sharing options...
JBalius Posted February 15, 2007 Share Posted February 15, 2007 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> Quote Link to comment Share on other sites More sharing options...
bizerk Posted February 15, 2007 Author Share Posted February 15, 2007 Great! That fixed the problem. I guess using the isset was not a good choice. When i replaced it with $_POST['Submit'], it worked FINE! thanks everyone -regards, BizErk Quote Link to comment 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.