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.

Photo

While loop issues in PHP...


  • Please log in to reply
4 replies to this topic

#1 KamakaZ

KamakaZ

  • Members
  • 739 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Victoria
  • Local time:06:09 AM

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++;
}
}

?>

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.


BC AdBot (Login to Remove)

 


#2 Romeo29

Romeo29

    Learning To Bleep


  • Members
  • 3,194 posts
  • OFFLINE
  •  
  • Gender:Not Telling
  • Location:127.0.0.1
  • Local time:02:09 PM

Posted 20 September 2009 - 09:11 AM

This loop is a forever loop.

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


#3 KamakaZ

KamakaZ
  • Topic Starter

  • Members
  • 739 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Victoria
  • Local time:06:09 AM

Posted 20 September 2009 - 05:46 PM

yeah i found that... after staring at it for a while...

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 groovicus

groovicus

  • Security Colleague
  • 9,963 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Centerville, SD
  • Local time:01:09 PM

Posted 20 September 2009 - 06:33 PM

After you discovered it, did you have the urge to jam a pencil in your eye? :thumbsup:

#5 KamakaZ

KamakaZ
  • Topic Starter

  • Members
  • 739 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Victoria
  • Local time:06:09 AM

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:

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.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users