I think it's just a simple mistake I've made, but until now I still can't get the solution why my last else if {} statement does not execute when it meets the condition.
It's my form. I have 3 form elements as options for users to enter value. They can choose either to upload which are text, photo, or movie. Here is my PHP:
if ( $this->input->post('text') !== '') {
//this executes fine when it meets the condition
} else if ( $this->input->post('photo') !== '' ) {
// this also works fine
} else if ( $this->input->post('video') !== '' ) {
/* however, I can't get to this condition when
the user chooses to upload the movie.
It always go the second condition.
*/
}
Edit:
Here's my view:
<form action="<?php echo base_url()?>action/post" method="post" enctype="multipart/form-data">
<ul class="nav nav-tabs">
<li class="active">
<a href="#status" data-toggle="tab">Update Status</a>
</li>
<li>
<a href="#photos" data-toggle="tab">Post Photos</a>
</li>
<li>
<a href="#videos" data-toggle="tab">Post Videos</a>
</li>
</ul>
<div class="tab-content">
<div class="tab-pane active" id="status">
<textarea name="text"></textarea>
</div>
<div class="tab-pane" id="photos">
<input type="file" name="photo" class="input" />
<input type="text" name="photos-detail" placeholder="description" />
</div>
<div class="tab-pane" id="videos">
<input type="file" name="video" class="input" />
<input type="text" name="videos-detail" placeholder="description" />
</div>
</div>
<button type="submit" class="btn btn-primary" name="post">Post</button>
</form>
Any idea would be really appreciated.
You cant check file inputs reliably like that. I usually check the file size to see if anything has been uploaded, so you could do something like this (should work):
if ( $this->input->post('text') !== '') {
//code
} else if((isset($_FILES["photo"]["size"])) && ($_FILES["photo"]["size"] > 0)){
// code 2
} else if((isset($_FILES["video"]["size"])) && ($_FILES["video"]["size"] > 0)){
// code 3
}
NOTE You can't just check the file size or you will get undefined index error - hence the isset()
If I use the same code the result that I get is that my view show me the entire code line.
if ( $usuario->party !== '') {
<a href="<?php echo base_url('vincular/party') ?>"><img src="<?php echo base_url('assets/img/link/sprite1_13.png') ?>"></a>
} else {
<a href="<?php echo base_url('vincular/party') ?>"><img src="<?php echo base_url('assets/img/link/party.png') ?>"></a>
}
If I don´t use my code works fine:
<?php foreach ($usuarios->result() as $usuario) { ?>
<div id="cuerpo" class="cuerpoMyPerfil">
<div id="columna1">
<div id="contenColumn1" class="corner">
<div class="myFoto">
<img src="<?php echo base_url('assets/img/testimonials/user.jpg') ?>" width="100%" height="auto" alt="nombre" /> </div>
<div class="myNombre">
<?php
echo $usuario->nombre . "<br/>";
echo $usuario->apellidos;
?>
</div>
<div class="myDescripcion">
<?php echo $usuario->acerca; ?>
</div>
if ( $usuario->party !== '') {
<a href="<?php echo base_url('vincular/party') ?>"><img src="<?php echo base_url('assets/img/link/sprite1_13.png') ?>"></a>
} else {
<a href="<?php echo base_url('vincular/party') ?>"><img src="<?php echo base_url('assets/img/link/party.png') ?>"></a>
}
<dl class="dl-vertical">
<!-- Verificar que tenga valores en la tabla vincular
Si lo trae, poner el ícono prendido, de lo contrario el apagado-->
<dt>
<a href="<?php echo base_url('vincular/dating') ?>"><img class="pull-right" src="<?php echo base_url('assets/img/link/love.png') ?>"></a></dt>
<dt><a href="<?php echo base_url('vincular/network') ?>"><img src="<?php echo base_url('assets/img/link/network.png') ?>"></a>
<a href="<?php echo base_url('vincular/friends') ?>"><img class="pull-right" src="<?php echo base_url('assets/img/link/friends.png') ?>"></a></dt>
</dl>
</div>
<div class='myTextInvi'>
<div class='textInvitacionActual floatL'>Tienes Invitaciones disponibles</div>
<div class='numInvitacionActual floatL' ><?php echo $usuario->disponibles; ?></div>
</div>
<div class='myBtnInvi'>
<a href="<?php echo base_url('oneperfil/invite') ?>">
<div class='textBtnInvitacion'>ENVIAR INVITACIÓN</div>
</a>
</div>
</div>
</div>
<?php } ?>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.