wmguk Posted August 20, 2007 Share Posted August 20, 2007 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? Quote Link to comment https://forums.phpfreaks.com/topic/65747-solved-elseif-help/ Share on other sites More sharing options...
Northern Flame Posted August 20, 2007 Share Posted August 20, 2007 what is $active for? is it post or get data? or what....? Quote Link to comment https://forums.phpfreaks.com/topic/65747-solved-elseif-help/#findComment-328427 Share on other sites More sharing options...
wmguk Posted August 20, 2007 Author Share Posted August 20, 2007 sorry, $active = $row['active']; the page takes the $login, checks the database, if a result is found, then it does the first script i posted Quote Link to comment https://forums.phpfreaks.com/topic/65747-solved-elseif-help/#findComment-328430 Share on other sites More sharing options...
Northern Flame Posted August 20, 2007 Share Posted August 20, 2007 <?php if(empty($active)){ /* put what you want displayed if active is empty */ } else{ if($active = 'yes'){ /* put what you want displayed if active = yes */ } elseif($active = 'no'){ /* put what you want displayed if active = no */ } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/65747-solved-elseif-help/#findComment-328431 Share on other sites More sharing options...
wmguk Posted August 20, 2007 Author Share Posted August 20, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/65747-solved-elseif-help/#findComment-328435 Share on other sites More sharing options...
Northern Flame Posted August 20, 2007 Share Posted August 20, 2007 does it give you an error message, or just a blank page? Quote Link to comment https://forums.phpfreaks.com/topic/65747-solved-elseif-help/#findComment-328437 Share on other sites More sharing options...
wmguk Posted August 20, 2007 Author Share Posted August 20, 2007 i get the html layout around the page, but it just doesnt display the message i want it to, Quote Link to comment https://forums.phpfreaks.com/topic/65747-solved-elseif-help/#findComment-328440 Share on other sites More sharing options...
chocopi Posted August 20, 2007 Share Posted August 20, 2007 maybe you should use == instead of = in your if statements Quote Link to comment https://forums.phpfreaks.com/topic/65747-solved-elseif-help/#findComment-328441 Share on other sites More sharing options...
wmguk Posted August 20, 2007 Author Share Posted August 20, 2007 ah yes, i spotted that, when the active = yes displayed the same message as active = no lol, however the if no result just doesnt seem to want to work... Quote Link to comment https://forums.phpfreaks.com/topic/65747-solved-elseif-help/#findComment-328443 Share on other sites More sharing options...
chocopi Posted August 20, 2007 Share Posted August 20, 2007 can you post your current code please Quote Link to comment https://forums.phpfreaks.com/topic/65747-solved-elseif-help/#findComment-328449 Share on other sites More sharing options...
wmguk Posted August 20, 2007 Author Share Posted August 20, 2007 <?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 } } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/65747-solved-elseif-help/#findComment-328451 Share on other sites More sharing options...
chocopi Posted August 20, 2007 Share Posted August 20, 2007 if $active has a a value are sure it is exactly 'yes' or 'no' Quote Link to comment https://forums.phpfreaks.com/topic/65747-solved-elseif-help/#findComment-328456 Share on other sites More sharing options...
wmguk Posted August 20, 2007 Author Share Posted August 20, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/65747-solved-elseif-help/#findComment-328457 Share on other sites More sharing options...
wmguk Posted August 20, 2007 Author Share Posted August 20, 2007 agggjhhhh, this is a nightmare.. i just cant understand this at all... Quote Link to comment https://forums.phpfreaks.com/topic/65747-solved-elseif-help/#findComment-328471 Share on other sites More sharing options...
Northern Flame Posted August 20, 2007 Share Posted August 20, 2007 if it is only yes or no, why would it be empty? Quote Link to comment https://forums.phpfreaks.com/topic/65747-solved-elseif-help/#findComment-328472 Share on other sites More sharing options...
wmguk Posted August 20, 2007 Author Share Posted August 20, 2007 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? Quote Link to comment https://forums.phpfreaks.com/topic/65747-solved-elseif-help/#findComment-328477 Share on other sites More sharing options...
chocopi Posted August 20, 2007 Share Posted August 20, 2007 it would be empty if your sql was wrong or your mysql_fetch_array you should double-check them Quote Link to comment https://forums.phpfreaks.com/topic/65747-solved-elseif-help/#findComment-328481 Share on other sites More sharing options...
wmguk Posted August 20, 2007 Author Share Posted August 20, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/65747-solved-elseif-help/#findComment-328485 Share on other sites More sharing options...
wmguk Posted August 20, 2007 Author Share Posted August 20, 2007 oh, and i just worked out the counter thingy ... but the display thing isnt working Quote Link to comment https://forums.phpfreaks.com/topic/65747-solved-elseif-help/#findComment-328486 Share on other sites More sharing options...
wmguk Posted August 20, 2007 Author Share Posted August 20, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/65747-solved-elseif-help/#findComment-328495 Share on other sites More sharing options...
keeB Posted August 20, 2007 Share Posted August 20, 2007 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 = ? Quote Link to comment https://forums.phpfreaks.com/topic/65747-solved-elseif-help/#findComment-328528 Share on other sites More sharing options...
wmguk Posted August 20, 2007 Author Share Posted August 20, 2007 if i view an active album i get active = yes, if i view a closed album i get active = no and if i view a made up album i get nothing at all. Quote Link to comment https://forums.phpfreaks.com/topic/65747-solved-elseif-help/#findComment-328542 Share on other sites More sharing options...
wmguk Posted August 20, 2007 Author Share Posted August 20, 2007 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 } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/65747-solved-elseif-help/#findComment-328556 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.