Log in

View Full Version : While error neverending?



bluewalrus
10-20-2008, 07:00 PM
I have this page http://www.bluewalrus.net/testing.php. Which comes from this page http://www.bluewalrus.net/log.html. Its suppose to write code for a web page based on how many photos the user inputs but right now its ignoring the number and just keeps writing no stopping. Also the if statement above isn't working either so I don't know if theres something wrong with my declarations at the top or if its something else? Any suggestions I appreciate the php is below. Also if you go to test it the username and password don't matter yet i'm going to add those in later so you can put anything you want or nothing.

<?php
$user = $_POST['user'];
$pass = $_POST['password'];
$event = $_POST['event'];
$maxnum = $_POST['totalphotos'];
$bp = $_POST['bigpic'];
$num = 01;
print '<link rel="stylesheet" type="text/css" href="/Agov3/scripts/box/css/lightbox.css"></link> <p><script type="text/javascript" src="Agov3/scripts/box/js/prototype.js"><!--//--></script><script type="text/javascript" src="Agov3/scripts/box/js/scriptaculous.js?load=effects,builder"><!--//--></script><script type="text/javascript" src="Agov3/scripts/box/js/lightbox.js"><!--//--></script>TEXT ABOUT EVENT</p><p><a title="" href="?pageID=gov3terminal&amp;L=3&amp;L0=Home&amp;L1=Media+Center&amp;L2=Videos&amp;sid=Agov3&amp;b=terminalcontent&amp;f=videos_&amp;csid=Agov3" target="_self"><img title="" height="15" alt="" hspace="2" src="http://www.mass.gov/Agov3/images/video_icon.GIF" width="14" border="0" /></a>&#160;<a title="" href="?pageID=gov3terminal&amp;L=3&amp;L0=Home&amp;L1=Media+Center&amp;L2=Videos&amp;sid=Agov3&amp;b=terminalcontent&amp;f=videos_' . $event . '&amp;csid=Agov3" target="_self">Go to the video from this event</a><br /><a title="" href="?pageID=gov3subtopic&amp;L=4&amp;L0=Home&amp;L1=Key+Priorities&amp;L2=World-Class+Education+-+The+Readiness+Project&amp;L3=The+Commonwealth+Readiness+Project&amp;sid=Agov3" target="_self"><img title="transcript icon" height="15" alt="transcript icon" hspace="2" src="http://www.mass.gov/Agov3/images/complete_text_icon.gif" width="14" border="0" /></a>&#160;<a href="?pageID=gov3subtopic&amp;L=4&amp;L0=Home&amp;L1=Key+Priorities&amp;L2=World-Class+Education+-+The+Readiness+Project&amp;L3=The+Commonwealth+Readiness+Project&amp;sid=Agov3" target="_self">Learn more about the Readiness Project and read the final reports</a><br /><a title="" href="?pageID=gov3terminal&amp;L=3&amp;L0=Home&amp;L1=Media+Center&amp;L2=Speeches&amp;sid=Agov3&amp;b=terminalcontent&amp;f=text_' . $event . '&amp;csid=Agov3" target="_blank"><img title="transcript icon" height="15" alt="transcript icon" hspace="2" src="http://www.mass.gov/Agov3/images/complete_text_icon.gif" width="14" border="0" /></a>&#160;<a href="?pageID=gov3terminal&amp;L=3&amp;L0=Home&amp;L1=Media+Center&amp;L2=Speeches&amp;sid=Agov3&amp;b=terminalcontent&amp;f=text_' .$event . '&amp;csid=Agov3" target="_blank">Read the transcript of the speech</a>&#160;(opens in a new window)<br /><a title="" href="?pageID=gov3pressrelease&amp;L=1&amp;L0=Home&amp;sid=Agov3&amp;b=pressrelease&amp;f=080625_education_reform3&amp;csid=Agov3" target="_blank"><img title="transcript icon" height="15" alt="transcript icon" hspace="2" src="http://www.mass.gov/Agov3/images/complete_text_icon.gif" width="14" border="0" /></a>&#160;<a href="?pageID=gov3pressrelease&amp;L=1&amp;L0=Home&amp;sid=Agov3&amp;b=pressrelease&amp;f=080625_education_reform3&amp;csid=Agov3" target="_blank">Read the press release</a><br /></p>';
if ($bp = "Yes") {
print '<h4>The "Big Picture"</h4><p>View a panoramic picture of the event.&#160;</p><table width="100%"><tbody><tr><td>&#160;<a title="" href="Agov3/images/' . $event . '_bp.jpg" rel="lightbox[roadtrip]"><img title="A panoramic view of the event." alt="A panoramic view of the event." src="/Agov3/images/' . $event .'_bplk.jpg" border="0" /></a></td></tr></tbody></table><br />';
}
while ( $num <= $maxnum )
{
print '<p>Click photo to open larger version.&#160; Right-click photo to download and save.<br /></p><table bordercolor="#c0c0c0" cellpadding="2" width="100%" border="1"><tbody><tr><td><a title="Info about photo" href="Agov3/images/' . $event . $num . 'lb.jpg" rel="lightbox[roadtrip]"><img title="Info about photo" height="133" alt="Info about photo" src="/Agov3/images/' . $event . $num . 'lk.jpg" width="200" border="0" /></a><center><a href="Agov3/images/' . $event . $num . 'web.jpg" target="_blank">Full Res</a></center></td><td>Info about photo</td></tr></tbody></table>';
}
?>

Jesdisciple
10-20-2008, 11:13 PM
$num never changes, thus the infinite loop. Regardless, a for loop is more appropriate. (Remove the earlier $num = 01; assignment.)
for ( $num = 1; $num <= $maxnum; $num++ )
{
print '<p>Click photo to open larger version. Right-click photo to download and save.<br /></p><table bordercolor="#c0c0c0" cellpadding="2" width="100%" border="1"><tbody><tr><td><a title="Info about photo" href="Agov3/images/' . $event . $num . 'lb.jpg" rel="lightbox[roadtrip]"><img title="Info about photo" height="133" alt="Info about photo" src="/Agov3/images/' . $event . $num . 'lk.jpg" width="200" border="0" /></a><center><a href="Agov3/images/' . $event . $num . 'web.jpg" target="_blank">Full Res</a></center></td><td>Info about photo</td></tr></tbody></table>';
}

bluewalrus
10-21-2008, 12:05 AM
oo thanks

Do you see anything wrong with the if statement its showing up no matter what right now? Maybe Something suppose to be different cause i'm using radio buttons?

[ICODE]if ($bp = 'Yes') {
print '<h4>The "Big Picture"</h4><p>View a panoramic picture of the event.&#160;</p><table width="100%"><tbody><tr><td>&#160;<a title="" href="Agov3/images/' . $event . '_bp.jpg" rel="lightbox[roadtrip]"><img title="A panoramic view of the event." alt="A panoramic view of the event." src="/Agov3/images/' . $event .'_bplk.jpg" border="0" /></a></td></tr></tbody></table><br />';
}

From the form page
[CODE]Big Picture: Yes:<input type="radio" name="bigpic" value="Yes" checked="checked" /> No:<input type="radio" name="bigpic" value="No" />

Jesdisciple
10-21-2008, 12:28 AM
Woops, I can't believe I forgot to look at that. if ($bp = "Yes") assigns "Yes" to $bp and then tests whether $bp is truthy (not unset, null, the empty string, or false). Since "Yes" is truthy, the block always executes.
if ($bp === "Yes")(The third = means the test is strict, which is usually better.)

bluewalrus
10-21-2008, 12:37 AM
ooo Thanks again