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 :/ Link to comment https://forums.phpfreaks.com/topic/38670-solved-if-else-statement-not-working-correctly/ 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. Link to comment https://forums.phpfreaks.com/topic/38670-solved-if-else-statement-not-working-correctly/#findComment-185708 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. Link to comment https://forums.phpfreaks.com/topic/38670-solved-if-else-statement-not-working-correctly/#findComment-185710 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? Link to comment https://forums.phpfreaks.com/topic/38670-solved-if-else-statement-not-working-correctly/#findComment-185711 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. :-\ Link to comment https://forums.phpfreaks.com/topic/38670-solved-if-else-statement-not-working-correctly/#findComment-185714 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> Link to comment https://forums.phpfreaks.com/topic/38670-solved-if-else-statement-not-working-correctly/#findComment-185719 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 Link to comment https://forums.phpfreaks.com/topic/38670-solved-if-else-statement-not-working-correctly/#findComment-185880 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.