Jump to content

[SOLVED] elseif help


wmguk

Recommended Posts

I have this code


        <?php 
include "admin/scripts/connection.php"; 
if (!$con) 
{ 
die( 'Could not connect: ' . mysql_error() ); 
}
mysql_select_db($db, $con); 

$result = mysql_query("SELECT * FROM album WHERE login = '$loginlower'");

while($row = mysql_fetch_array($result)) 
{ 
$active = $row['active']; 
$ceremony = $row['ceremony'];
if ($active == 'yes') 
{
?><table width="750" border="0" align="center" cellpadding="0" cellspacing="0">
          <tr>
            <td width="250"><iframe width="150" height="450" frameborder="0" name="thumbs" src="admin/gallery/thumb.php?login=<? echo $login ; ?>&ceremony=<? echo $ceremony ; ?>"></iframe></td>
            <td width="500"><iframe width="600" height="450" frameborder="0" name="order" src="gallery/intro.php"></iframe></td>
          </tr>
        </table><?php
}
elseif ($active == 'no') 
{
?><table width="750" border="0" cellspacing="0" cellpadding="0">
 <tr>
   <td><p class="header"><BR /><br />Welcome to Imagine Wedding Photography.</p>
   <p class="main">Unfortunatly the images you wish to see are currently unavailable, undergoing the last final few tweeks to get them perfect for you.</p>
   <p class="main">Please either enter your email address below, to be notified when they become available, or check back soon.  </p>
     <form name="contact" method="post" action="contact.php">
     <input type="text" class="main" name="email">
  <input type="hidden"  name="interested" value="<? echo $login ; ?>"> 
  <input type="submit" class="main" name="submit" value="Contact Us" />     
     </form>    <p> </p></td>
 </tr>
</table>
<?php
}
else 
{
?>
<table width="750" border="0" cellspacing="0" cellpadding="0">
 <tr>
   <td><p class="header"><BR /><br />Welcome to Imagine Wedding Photography.</p>
   <p class="main">There appears to have been an error, the album you are searching for does not exist. Please press try again below.</p>
       <FORM METHOD="POST" NAME="AlbumSelect" ACTION="gallery.php">
	<table width="139" border="0" cellspacing="0" cellpadding="0">
         <tr>
           <td class="main"><div align="center"><span class="style1">Enter Album Name:</span><br />
           </div></td>
         </tr>
         <tr>
           <td class="main"><div align="center">
               <input type="text" name="login" size="15" />
           </div></td>
         </tr>
         <tr>
           <td class="main"><div align="center">
               <input type="submit" name="LoginEnter" value="Access Album"/>
           </div></td>
         </tr>
       </table></FORM>
	</td>
 </tr>
</table>
<?php
}
?>

 

Obviously if active = yes then do this, but if active = no then do this, - if there is no record at all then do this...

 

but the final one doesnt work, if there is no active it should say you have entered the wrong code, but it doesnt display anything..

 

any thoughts?

Link to comment
Share on other sites

just did that, but its not worked, its exactly like the first script i posted... I'm not sure if its something to do with if there is no result at all then display

 

"you entered an incorrect code"

 

however if there is a result, the if active = yes "echo this is active"

and if there is a result but is active = no then echo this isnt active..

 

its most confusing :)

Link to comment
Share on other sites

         <?php 
include "admin/scripts/connection.php"; 
if (!$con) 
{ 
  die( 'Could not connect: ' . mysql_error() ); 
   }
mysql_select_db($db, $con); 

$result = mysql_query("SELECT * FROM album WHERE login = '$loginlower'");

while($row = mysql_fetch_array($result)) 
{ 
$active = $row['active']; 
$ceremony = $row['ceremony'];

if(empty($active)){
?>
<table width="750" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td><p class="header"><BR /><br />Welcome to Imagine Wedding Photography.</p>
    <p class="main">There appears to have been an error, the album you are searching for does not exist. Please press try again below.</p>
        <FORM METHOD="POST" NAME="AlbumSelect" ACTION="gallery.php">
	<table width="139" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td class="main"><div align="center"><span class="style1">Enter Album Name:</span><br />
            </div></td>
          </tr>
          <tr>
            <td class="main"><div align="center">
                <input type="text" name="login" size="15" />
            </div></td>
          </tr>
          <tr>
            <td class="main"><div align="center">
                <input type="submit" name="LoginEnter" value="Access Album"/>
            </div></td>
          </tr>
        </table></FORM>
	</td>
  </tr>
</table>
<?php
} else{
    if($active == 'yes'){
?><table width="750" border="0" align="center" cellpadding="0" cellspacing="0">
           <tr>
             <td width="250"><iframe width="150" height="450" frameborder="0" name="thumbs" src="admin/gallery/thumb.php?login=<? echo $login ; ?>&ceremony=<? echo $ceremony ; ?>"></iframe></td>
             <td width="500"><iframe width="600" height="450" frameborder="0" name="order" src="gallery/intro.php"></iframe></td>
           </tr>
         </table>
<?php
} elseif($active == 'no'){
?>
<table width="750" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td><p class="header"><BR /><br />Welcome to Imagine Wedding Photography.</p>
    <p class="main">Unfortunatly the images you wish to see are currently unavailable, undergoing the last final few tweeks to get them perfect for you.</p>
    <p class="main">Please either enter your email address below, to be notified when they become available, or check back soon.  </p>
      <form name="contact" method="post" action="contact.php">
      <input type="text" class="main" name="email">
  <input type="hidden"  name="interested" value="<? echo $login ; ?>"> 
  <input type="submit" class="main" name="submit" value="Contact Us" />     
      </form>    <p> </p></td>
  </tr>
</table>
<?php
}
}
}
?>

Link to comment
Share on other sites

yup defenatly, basically you create an album and its default is no, then you click a button which does an UPDATE to the database and changes it to yes, ive made sure there are no capitals and Ive been in to the database using phpmyadmin and its right, just yes or no.

 

the only thing i can think of is that if the code they entered isnt in the database, it cant be active, because its simply not there...

 

i just dont know why it wont display the text, where as the rest of the page shows up

Link to comment
Share on other sites

it wouldnt be, its either a yes or no, or its not in the database at all... thats whats throwing me, lol, the empty bit was the script you gave me :)

 

----

the other thing im trying to do with this script is a page views counter.

 

very basic, in the database i have created a field called counters and by default it is 0

 

what i need to do is simple, $counters = $counters++ but then i need to run an UPDATE script, on that, if active == yes...

 

any ideas?

Link to comment
Share on other sites

what would be empty?

 

im lost lol, all im doing is querying the db = does login = abc exist, if yes then is it active, yes or no, if active = yes, display "ACTIVE", if active = no, display "NOT ACTIVE" and if abc doesnt even exist display "DOESNT EXIST".

 

thats whats got me... the active = yes and no works, its just the doesnt exist bit

Link to comment
Share on other sites

ah ha, I also have to check if there is a password on that album, so my code now looks like this:

 

 <?php 
include "admin/scripts/connection.php"; 
if (!$con) 
{ 
  die( 'Could not connect: ' . mysql_error() ); 
   }
mysql_select_db($db, $con); 

$result = mysql_query("SELECT * FROM album WHERE login = '$loginlower'");

while($row = mysql_fetch_array($result)) 
{ 
$active = $row['active']; 
$counters = $row['counters'];
$ceremony = $row['ceremony'];
$password = $row['password'];

$counterupdate = ++$counters;

if(empty($active)){
?>
<table width="750" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td><p class="header"><BR /><br />Welcome to Imagine Wedding Photography.</p>
    <p class="main">There appears to have been an error, the album you are searching for does not exist. Please press try again below.</p>
        <FORM METHOD="POST" NAME="AlbumSelect" ACTION="gallery.php">
	<table width="139" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td class="main"><div align="center"><span class="style1">Enter Album Name:</span><br />
            </div></td>
          </tr>
          <tr>
            <td class="main"><div align="center">
                <input type="text" name="login" size="15" />
            </div></td>
          </tr>
          <tr>
            <td class="main"><div align="center">
                <input type="submit" name="LoginEnter" value="Access Album"/>
            </div></td>
          </tr>
        </table></FORM>
	</td>
  </tr>
</table>
<?php
} else{
    if($active == 'yes' && $password ==""){
?><table width="750" border="0" align="center" cellpadding="0" cellspacing="0">
           <tr>
             <td width="250"><iframe width="150" height="450" frameborder="0" name="thumbs" src="admin/gallery/thumb.php?login=<? echo $login ; ?>&ceremony=<? echo $ceremony ; ?>&counters=<?php echo $counterupdate ; ?>"></iframe></td>
             <td width="500"><iframe width="600" height="450" frameborder="0" name="order" src="gallery/intro.php"></iframe></td>
           </tr>
         </table>
<?php
} elseif($active == 'yes' && $password =="*"){
?><table width="750" border="0" align="center" cellpadding="0" cellspacing="0">
           <tr>
             <td width="250">ENTER PASSWORD</td>
           </tr>
         </table>
<?php
} elseif($active == 'no'){
?>
<table width="750" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td><p class="header"><BR /><br />Welcome to Imagine Wedding Photography.</p>
    <p class="main">Unfortunatly the images you wish to see are currently unavailable, undergoing the last final few tweeks to get them perfect for you.</p>
    <p class="main">Please either enter your email address below, to be notified when they become available, or check back soon.  </p>
      <form name="contact" method="post" action="contact.php">
      <input type="text" class="main" name="email">
  <input type="hidden"  name="interested" value="<? echo $login ; ?>"> 
  <input type="submit" class="main" name="submit" value="Contact Us" />     
      </form>    <p> </p></td>
  </tr>
</table>
<?php
}
}
}
?>

 

and guess what, if active = yes and there is a password, it doesnt display my error message, it displays a blank page...

 

hmm, this is odd, its like my elseif statements arent working correctly

Link to comment
Share on other sites

Try this:

 

<?php 
include "admin/scripts/connection.php"; 
if (!$con) 
{ 
  die( 'Could not connect: ' . mysql_error() ); 
   }
mysql_select_db($db, $con); 

$result = mysql_query("SELECT * FROM album WHERE login = '$loginlower'");

while($row = mysql_fetch_array($result)) 
{ 
$active = $row['active']; 
$counters = $row['counters'];
$ceremony = $row['ceremony'];
$password = $row['password'];

$counterupdate = ++$counters;

die ("active = " . $active);

 

active = ?

Link to comment
Share on other sites

Whoo Hooo, Finally sorted it!!!

 

needed to add

if (!mysql_num_rows($result)) {

so that if there is no result, then show this......

 

Thank god, and just incase anyone else has the same trouble, here is the complete script :)

 

<?php

include "admin/scripts/connection.php"; 
if (!$con) 
{ 
 die( 'Could not connect: ' . mysql_error() ); 
  }
mysql_select_db($db, $con); 

$result = mysql_query("SELECT * FROM album WHERE login = '$loginlower'");

if (!mysql_num_rows($result)) {
?>
<table width="750" border="0" cellspacing="0" cellpadding="0">
 <tr>
   <td><p class="header"><BR /><br />Welcome to the website.</p>
   <p class="main">It would appear you have entered the information incorrectly. The album you are looking for cannot be found.</p>
   <p class="main">Please re-enter the album name below to try again or contact <a href="mailto:the@website.co.uk">Customer Services</a></p>
   <FORM METHOD="POST" NAME="AlbumSelect" ACTION="gallery.php">
	<table width="139" border="0" cellspacing="0" cellpadding="0">
         <tr>
           <td class="main"><div align="center"><span class="style1">Enter Album Name:</span><br />
           </div></td>
         </tr>
         <tr>
           <td class="main"><div align="center">
               <input type="text" name="login" size="15" />
           </div></td>
         </tr>
         <tr>
           <td class="main"><div align="center">
               <input type="submit" name="LoginEnter" value="Access Album"/>
           </div></td>
         </tr>
       </table></FORM></td>
 </tr>
</table>
<?php
}


while($row = mysql_fetch_array($result)) 
{ 
$active = $row['active']; 
$counters = $row['counters'];
$ceremony = $row['ceremony'];
$password = $row['password'];

$counterupdate = ++$counters;

if($active == 'yes' && $password =="X"){
?><table width="750" border="0" align="center" cellpadding="0" cellspacing="0">
          <tr>
            <td width="250"><iframe width="150" height="450" frameborder="0" name="thumbs" src="admin/gallery/thumb.php?login=<? echo $login ; ?>&ceremony=<? echo $ceremony ; ?>&counters=<?php echo $counterupdate ; ?>"></iframe></td>
            <td width="500"><iframe width="600" height="450" frameborder="0" name="order" src="gallery/intro.php"></iframe></td>
          </tr>
        </table>
<?php
} elseif($active == 'yes' && $password !="X"){
?><table width="750" border="0" align="center" cellpadding="0" cellspacing="0">
          <tr>
            <td width="250"><br /><br /><form name="contact" method="post" action="admin/scripts/verify.php">
     <input type="password" class="main" name="password">
  <input type="hidden"  name="login" value="<? echo $login ; ?>"> 
 	  <input type="hidden"  name="ceremony" value="<? echo $ceremony ; ?>"> 
 	  <input type="hidden"  name="counters" value="<? echo $counterupdate ; ?>"> 
  <input type="submit" class="main" name="submit" value="Verify the Password" />     
     </form>  </td>
          </tr>
        </table>
<?php
} elseif($active == 'no'){
?>
<table width="750" border="0" cellspacing="0" cellpadding="0">
 <tr>
   <td><p class="header"><BR /><br />Welcome to the website.</p>
   <p class="main">Unfortunatly the images you wish to see are currently unavailable, undergoing the last final few tweeks to get them perfect for you.</p>
   <p class="main">Please either enter your email address below, to be notified when they become available, or check back soon.  </p>
     <form name="contact" method="post" action="contact.php">
     <input type="text" class="main" name="email">
  <input type="hidden"  name="interested" value="<? echo $login ; ?>"> 
  <input type="submit" class="main" name="submit" value="Contact Us" />     
     </form>    <p> </p></td>
 </tr>
</table>
<?php
}
}
?>

Link to comment
Share on other sites

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.