Jump to content

[SOLVED] Odd if..elseif problem


MishieMoo

Recommended Posts

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>

 

Link to comment
https://forums.phpfreaks.com/topic/89616-solved-odd-ifelseif-problem/
Share on other sites

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 />';
}

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.