BleepingComputer.com: While loop issues in PHP...

Jump to content


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.

Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

While loop issues in PHP...

#1 User is offline   KamakaZ 

  • Senior Member
  • PipPipPipPip
  • Find Topics
  • Group: Members
  • Posts: 548
  • Joined: 26-August 08
  • Gender:Male
  • Location:Victoria

Posted 10 September 2009 - 08:23 PM

Any ideas why this is resulting in me having pages of "inserted"? I was under the impression that when $i=5 it shouldn't print any more...

if (isset($_POST['submit'])) { 
 
while($i<=5) {
 
 
$i=1;
$fld = 'pick'.$i;
$fld1 = 'addr'.$i;
$fld2 = 'dest'.$i;
$fld3 = 'tonn'.$i;
$fld4 = 'driv'.$i;
$fld5 = 'invn'.$i;
$fld6 = 'subc'.$i;
$fld7 = 'span'.$i;
 
 
if(isset($_POST[$fld])) {
   mysql_query("INSERT INTO `jobs` (`ts`, `pick`, `addr`, `dest`, `tonn`, `driv`, `invc`, `subc`, `span`, `completed`) VALUES ('ts', '".$_POST["pick".$i]."', '".$_POST["addr".$i]."', '".$_POST["dest".$i]."', '".$_POST["tonn".$i]."', '".$_POST["driv".$i]."', '".$_POST["invn".$i]."', '".$_POST["subc".$i]."', '".$_POST["span".$i]."', 'no')", $connect);
   echo ("<br>Inserted<br>");
  }
 
$i++;
}
}

?>

If I am helping you and don't reply in 24 hours please send me a PM

There's no place like 127.0.0.1
There are 10 types of people in the world, those that can read binary, and those who can't.

#2 User is offline   Romeo29 

  • Learning To Bleep
  • PipPipPipPipPipPip
  • Find Topics
  • Group: BC Advisor
  • Posts: 2,814
  • Joined: 06-July 08
  • Gender:Not Telling
  • Location:127.0.0.1

Posted 20 September 2009 - 09:11 AM

This loop is a forever loop.

while (i <= 5){
   i = 1; //look mom, no hands
   i++;
}

[url="http://www.avast.com/"]avast! free antivirus[/url]

#3 User is offline   KamakaZ 

  • Senior Member
  • PipPipPipPip
  • Find Topics
  • Group: Members
  • Posts: 548
  • Joined: 26-August 08
  • Gender:Male
  • Location:Victoria

Posted 20 September 2009 - 05:46 PM

yeah i found that... after staring at it for a while...
If I am helping you and don't reply in 24 hours please send me a PM

There's no place like 127.0.0.1
There are 10 types of people in the world, those that can read binary, and those who can't.

#4 User is offline   groovicus 

  • Hail Groovicus!
  • PipPipPipPipPipPip
  • Find Topics
  • Group: Moderator
  • Posts: 9,522
  • Joined: 05-June 04
  • Gender:Male
  • Location:Centerville, SD

Posted 20 September 2009 - 06:33 PM

After you discovered it, did you have the urge to jam a pencil in your eye? :thumbsup:
"Take the risk of thinking for yourself, much more happiness, truth, beauty, and wisdom will come to you that way" - Christopher Hitchens

#5 User is offline   KamakaZ 

  • Senior Member
  • PipPipPipPip
  • Find Topics
  • Group: Members
  • Posts: 548
  • Joined: 26-August 08
  • Gender:Male
  • Location:Victoria

Posted 20 September 2009 - 06:35 PM

hahaha indeed i did... closed the if statement above the $i++ and hey look it works now :thumbsup:
If I am helping you and don't reply in 24 hours please send me a PM

There's no place like 127.0.0.1
There are 10 types of people in the world, those that can read binary, and those who can't.

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users