MishieMoo Posted February 5, 2008 Share Posted February 5, 2008 Okay so I have a feature on my site where people can either upload their own avatar (where I check the files and all) or enter a url for a remotely hosted avatar. I've been trying to get it to work so that the upload script will only run if there is an uploaded file, and there is not a url entered, and vice versa for the url. For some reason, when I have both fields filled in, it will run the query for the remote url, even though it shouldn't. Here's the code with only the necessary parts shown. I edited it down for convenience <?php if (isset($_POST['submit'])){ //If the form has been submitted if((isset($_POST['avatar'])) && (isset($_POST['url']))){ echo'<div class="error">ERROR: You must either input a url or upload a file.</div><br />'; } elseif((isset($_POST['avatar'])) && (!isset($_POST['url']))) { //upload file code here } elseif((isset($_POST['url'])) && (!isset($_POST['avatar']))){ //add a url to the database } else{ echo'<div class="error">ERROR: You must either input a url or upload a file.</div><br />'; } }?> <div class="contenttable"><div class="tabletop">Custom Avatar Chooser</div> <form method="post" action="?place=forums"> <em>Please select your .jpg/gif/png avatar. The maximum size is 100px by 100px and 15kb.</em><br /> <table cellspacing="0" cellpadding="0" border="0" style="text-align:left"><tr><td> Upload: </td><td><input type="file" name="avatar" /></td></tr> <tr><td>URL:</td><td><input type="text" name="url" /></td></tr> <tr><td colspan="2"><input type="submit" name="submit" value="Submit"></td></tr></table> </form></div> Quote Link to comment https://forums.phpfreaks.com/topic/89616-solved-odd-ifelseif-problem/ Share on other sites More sharing options...
teng84 Posted February 5, 2008 Share Posted February 5, 2008 try, i clean your code if (isset($_POST['submit'])){ if(isset($_POST['avatar']){ if(isset($_POST['url'])){ echo'<div class="error">ERROR: You must either input a url or upload a file.</div><br />'; }elseif(!isset($_POST['url'])){ //upload file code here } } } elseif(!isset($_POST['avatar'])){ if(isset($_POST['url'])){ //add a url to the database } } else{ echo'<div class="error">ERROR: You must either input a url or upload a file.</div><br />'; } Quote Link to comment https://forums.phpfreaks.com/topic/89616-solved-odd-ifelseif-problem/#findComment-459166 Share on other sites More sharing options...
MishieMoo Posted February 5, 2008 Author Share Posted February 5, 2008 Nope. It still updates to the URL and displays the success message. Quote Link to comment https://forums.phpfreaks.com/topic/89616-solved-odd-ifelseif-problem/#findComment-459173 Share on other sites More sharing options...
revraz Posted February 5, 2008 Share Posted February 5, 2008 Put an echo in each part to see where it's failing. Quote Link to comment https://forums.phpfreaks.com/topic/89616-solved-odd-ifelseif-problem/#findComment-459175 Share on other sites More sharing options...
MishieMoo Posted February 5, 2008 Author Share Posted February 5, 2008 Okay for some reason it's not recognizing the fact that there's a file to be uploaded. $_POST['avatar'] isn't being set even if it's the only field that I'm entering anything in. Quote Link to comment https://forums.phpfreaks.com/topic/89616-solved-odd-ifelseif-problem/#findComment-459182 Share on other sites More sharing options...
schilly Posted February 5, 2008 Share Posted February 5, 2008 print_r($_POST) and see what it says. Is the field defined correctly? Could try using isset($_FILES['file']) instead? Quote Link to comment https://forums.phpfreaks.com/topic/89616-solved-odd-ifelseif-problem/#findComment-459200 Share on other sites More sharing options...
MishieMoo Posted February 5, 2008 Author Share Posted February 5, 2008 That was it. Duh, it's not $_POST its $_FILES. I feel so stupid. Thanks + Quote Link to comment https://forums.phpfreaks.com/topic/89616-solved-odd-ifelseif-problem/#findComment-459207 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.