Jump to content

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

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.