#16
  1. Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jan 2004
    Location
    New Springfield, OH
    Posts
    1,175
    Rep Power
    1469
    Originally Posted by Axweildr
    Notepad ++ roxxorz

    Personally don't do any coding in Dreamweaver, can only assume it's come on leaps and bounds since I started looking at it

    To my knowledge CC is mostly a rebranding exercise to take advantage of cloud computing, and everyone who bought the application, because now we're looking at a different licensing model

    Have a look at Eclipse if you want an IDE
    YMMV
    I agree with Notepad++ if you're just looking for an editor.

    Codelobster is nice for a lightweight IDE.

    For a full IDE, I prefer Netbeans over Eclipse for PHP. It seems to run faster for me. But both are pretty good on features. I tend to use Eclipse for Java development so I'm not suggesting it's a bad choice.
    Don't like me? Click it.

    Scripting problems? Windows questions? Ask the Windows Guru!

    Stay up to date with all of my latest content. Follow me on Twitter!

    Help us help you! Post your exact error message with these easy tips!
  2. #17
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2013
    Posts
    33
    Rep Power
    1

    automatically created by dreamweaver


    ok here we go with a new registration page that I just created in Dreamweaver. Please bare in mind, I noticed that Dreamweaver used mysql functions by default. I guess the team at Adobe doesn't see a need to upgrade this side of their product and concentrating more on bings and bangs of what people can get out css and their new designer.

    Nevertheless here is it: this is what I am starting with as a guy with no experience. I tested the page and it works fine. The first thing that will be obvious is that there is no protection for the password.

    <EDIT:> I just also finished reading that I should be using Jquery and or Ajax or maybe they are the same...(I haven't figured that one yet lol) ... to return a message if the username is already taken or if the passwords don't match. Where would be a good place to start reading about implementing this with Ajax?</Edit>

    this is where I am at. I have been reading since this morning (again lol) and following Jacques advices tried to stay away from tutorials who offer solutions that aren't exactly solutions. I was able to figure out a site that can reverse an md5 password with just one click, so obviously md5 is garbage. I read that Crypt is much better; but then they started talking about (3) and Blowfishes and I got lost.

    in order to move forward with this project I need to understand what method is the safest today and how to implement it on this page. once I have that figured out then seeing the codes I will have a frame of reference to research it deeper and actually understand what it is I just applied as far as protection is concerned on my page. Never know! I might even come up with something of my own to even further this protection.
    PHP Code:
    <?php require_once('../Connections/connect.php'); ?>
    <?php
    if (!function_exists("GetSQLValueString")) {
    function 
    GetSQLValueString($theValue$theType$theDefinedValue ""$theNotDefinedValue ""
    {
      if (
    PHP_VERSION 6) {
        
    $theValue get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
      }

      
    $theValue function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

      switch (
    $theType) {
        case 
    "text":
          
    $theValue = ($theValue != "") ? "'" $theValue "'" "NULL";
          break;    
        case 
    "long":
        case 
    "int":
          
    $theValue = ($theValue != "") ? intval($theValue) : "NULL";
          break;
        case 
    "double":
          
    $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
          break;
        case 
    "date":
          
    $theValue = ($theValue != "") ? "'" $theValue "'" "NULL";
          break;
        case 
    "defined":
          
    $theValue = ($theValue != "") ? $theDefinedValue $theNotDefinedValue;
          break;
      }
      return 
    $theValue;
    }
    }

    // *** Redirect if username exists
    $MM_flag="MM_insert";
    if (isset(
    $_POST[$MM_flag])) {
      
    $MM_dupKeyRedirect="registration.php";
      
    $loginUsername $_POST['username'];
      
    $LoginRS__query sprintf("SELECT username FROM tenants WHERE username=%s"GetSQLValueString($loginUsername"text"));
      
    mysql_select_db($database_connect$connect);
      
    $LoginRS=mysql_query($LoginRS__query$connect) or die(mysql_error());
      
    $loginFoundUser mysql_num_rows($LoginRS);

      
    //if there is a row in the database, the username was found - can not add the requested username
      
    if($loginFoundUser){
        
    $MM_qsChar "?";
        
    //append the username to the redirect page
        
    if (substr_count($MM_dupKeyRedirect,"?") >=1$MM_qsChar "&";
        
    $MM_dupKeyRedirect $MM_dupKeyRedirect $MM_qsChar ."requsername=".$loginUsername;
        
    header ("Location: $MM_dupKeyRedirect");
        exit;
      }
    }

    $editFormAction $_SERVER['PHP_SELF'];
    if (isset(
    $_SERVER['QUERY_STRING'])) {
      
    $editFormAction .= "?" htmlentities($_SERVER['QUERY_STRING']);
    }

    if ((isset(
    $_POST["MM_insert"])) && ($_POST["MM_insert"] == "registrationf")) {
      
    $insertSQL sprintf("INSERT INTO tenants (username, password) VALUES (%s, %s)",
                           
    GetSQLValueString($_POST['username'], "text"),
                           
    GetSQLValueString($_POST['password'], "text"));

      
    mysql_select_db($database_connect$connect);
      
    $Result1 mysql_query($insertSQL$connect) or die(mysql_error());
    }

    mysql_select_db($database_connect$connect);
    $query_rstenants "SELECT username, password FROM tenants";
    $rstenants mysql_query($query_rstenants$connect) or die(mysql_error());
    $row_rstenants mysql_fetch_assoc($rstenants);
    $totalRows_rstenants mysql_num_rows($rstenants);
    ?>
    <!doctype html>
    <!--[if lt IE 7]> <html class="ie6 oldie"> <![endif]-->
    <!--[if IE 7]>    <html class="ie7 oldie"> <![endif]-->
    <!--[if IE 8]>    <html class="ie8 oldie"> <![endif]-->
    <!--[if gt IE 8]><!-->
    <html class="">
    <!--<![endif]-->
    <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>registration</title>
    <link href="../boilerplate.css" rel="stylesheet" type="text/css">
    <link href="../css/css.css" rel="stylesheet" type="text/css">
    <!-- 
    To learn more about the conditional comments around the html tags at the top of the file:
    paulirish.com/2008/conditional-stylesheets-vs-css-hacks-answer-neither/

    Do the following if you're using your customized build of modernizr (http://www.modernizr.com/):
    * insert the link to your js here
    * remove the link below to the html5shiv
    * add the "no-js" class to the html tags at the top
    * you can also remove the link to respond.min.js if you included the MQ Polyfill in your modernizr build 
    -->
    <!--[if lt IE 9]>
    <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
    <![endif]-->
    <script src="../respond.min.js"></script>
    </head>
    <body>
    <div class="gridContainer clearfix">
      <header id="header" class="fluid">Please Register</header><div id="formdiv" class="fluid">
        <form action="<?php echo $editFormAction?>" id="registrationf" name="registrationf" method="POST">
        Username:<input name="username" type="text" required id="username" form="registrationf"><br/>
        Password:<input name="password" type="password" required id="password" form="registrationf"><br/>
        Re-enter Password:<input name="password2" type="password" required id="password2" form="registrationf"><br/>
        <input name="submit" type="submit" form="registrationf" value="submit">
        <input type="hidden" name="MM_insert" value="registrationf">
        </form>
      </div>
    </div>
    </body>
    </html>
    <?php
    mysql_free_result
    ($rstenants);
    ?>
  4. #18
  5. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,911
    Rep Power
    1045
    When you discover you're riding a dead horse, the best strategy is to dismount.

    I don't understand why you keep fumbling with that code after we've all come to the conclusion that it's crap.

    If Dreamweaver somehow doesn't allow you to write proper code, then it's not suitable for programming. You've already got several suggestions for good editors and IDEs. Choose one. Notepad++ is probably the easiest solution for now.

    After you've installed Notepad++, I strongly suggest you start with an empty script. You don't have to delete the old one, but you should leave it for now. Don't waste your time with wrong techniques. Spend it on learning correct PHP.

    The first thing to learn is how to access a MySQL database with PHP. I gave you a link for that. In practice, you first need to choose between PDO and MySQLi. And then you should read up on the basics of the database extension you've chosen. Don't worry, it's not difficult at all. It's actually much simpler than the weird functions you currently use.

    All the other stuff comes later. You first need to get the basics right. It doesn't make sense to write a complex application when the basic functionalities are all wrong.
  6. #19
  7. Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jan 2004
    Location
    New Springfield, OH
    Posts
    1,175
    Rep Power
    1469
    I agree. Quit using pre-written code. Start your own page. Take a look around Php.net if you really want sample code.

    Don't worry about AJAX. Front-end work is pointless if your backend doesn't function.
    Don't like me? Click it.

    Scripting problems? Windows questions? Ask the Windows Guru!

    Stay up to date with all of my latest content. Follow me on Twitter!

    Help us help you! Post your exact error message with these easy tips!
  8. #20
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2013
    Posts
    33
    Rep Power
    1

    I think I am the lamest dude here on this site.


    Language barrier between a newbie and the pros.

    I thought I should write a paragraph or two about how newbie can communicate his logic with the skilled code writers. I have personally been trying to learn how to write codes for about 4 years; ever since I developed my first desktop Microsoft Access application. The problem with my learning experience is that I haven’t learned anything. I segway into web programming about a month ago and been at it for at least 6-8 hours a day 7 days a week ever since. I am not going to quit! What have I learned so far? I know how to open a php line and type “hello world” and have it show in my screen. Meanwhile, feeling frustrated about it all I went and got myself a Dreamweaver subscription in hope that the program will get me started on my project with all the bell and whistles. I soon found out that no matter what, I need code writing skills in order to process data. There are thousands of people online who are willing to help. It’s great! One thing though: You don’t learn anything by asking someone on how to write a function that will make your webpage work. All you are doing is basically copying the codes someone else wrote for you and since you have no frame of reference to understand the code, the explanation that comes with might as well be in a foreign tongue; and you learned nothing.

    Let’s look at it from a newbie’s perspective:
    Driving a car is common knowledge. Everyone knows most cars need a key to start the engine and drive away. The majority of people don’t have to know how an engine or a transmission work, they just need to put it in the right gear to drive. Now, let’s say you bring an aboriginal from the Amazon. Someone who has never seen, or heard of cars before. You tell the aboriginal that this is a vehicle. You climb inside and it takes you where you want to go. You open the door and tell the aboriginal to sit behind the wheel, “let’s go for a ride, I will teach you how to drive.” The aboriginal gets totally lost. He looks around and think “I would much rather sit on the roof, that way I can see my preys better.” You have to explain to him that the controls of the car are inside the car and hush him along. Then the aboriginal ask “why aren’t we moving?” You tell him while laughing “Well you have to start the car first with this key.” “Why do you need a key to start the car? Why doesn’t it go by itself? What is a key anyway?” The aboriginal never seen a key before either. They don’t use keys in the Amazon. Well then you tell him never mind that. lets just go for a ride. In your head you want to take the aboriginal for a ride but on his side he is still thinking how crazy it is to use a little piece of metal with teeth to go somewhere. “No matter, let’s just start the car and go” The aboriginal say ok but nothing happen. You have to show him how to put it in gear and press the gas pedal to go.” The gas pedal? Why do I need to push on a gas pedal to go forward? What is gas anyway? Now you’ve done it! now you are going to have to explain about fossil fuel and refineries and economics and working for a living and that could take months if not a lifetime to answer all the aboriginal’s questions.

    You see, when you talk to a newbie about how to write codes, we all feel like we are aboriginal from the Amazon. We don’t know nothing about everything. What happen with most people with good heart and free time to teach newbies is they try to solve someone’s problem by providing codes instead of direction on how to have him come up with his own codes.

    I been at it for over 4 years and I still don’t know where to start. I read and read and read and read and looked at videos everyday but still today I can’t write a line of code to save my life. It’s great to do exercises and read about functions and have “hello world” pop up on your screen but what is this for if I never move forward in learning?

    Building a house is easy and progressive: You choose a ground, you lay out the foundation, you frame the house, you insulate it, add plumbing, electricity, hvac…. and you end up with a house at the end. The way it’s been for me and writing computer codes is like having all the material and all the tools sitting all mixed up in a big hole I dug for myself and can’t figure out for the world why can’t I use my drill to paint the walls of my house that is not built yet.

    Where do you start to learn? How do you learn how to write code? There is no logic to this logical language. All of you who know how to write code must have started somewhere? It doesn’t matter how much I read and try to learn because every time I try to learn about something I have ten more questions and go look for answers on those answers provoke 100 more questions that I can understand because I haven’t started to learn about the basic yet. But I can’t learn about the basic because I don’t know where to start since I don’t understand what is what in this crazy world of computer code writing. Anyway, this was my lame attempt to display how a newbie think in regard to computer language.

    EDIT: here is a very good example of what I am trying to say:

    extract fromW3School.com in PHP



    The strlen() function returns the length of a string, in characters.

    The example below returns the length of the string "Hello world!":

    PHP Code:
    <?php
    echo strlen("Hello world!");
    ?>
    Result: 12

    Questions:

    1-Why would I ever need to know how many letters there is in a string?

    2- why does the function measures the content by characters? why not use inches or centimeter instead?

    3- Why put "hello world" between braces?

    4- Why put double quotes when everywhere else people are using single quote marks

    5- then I have an answer: 12
    how is that relevant or why should I use the number (12) in a form or in a procedure where I am trying to find out if a field has a value = to what a user has inputted in a form? is this something that will help me figure out if a tenant paid his rent last month? like as in if(strlen() = 3) then yes the guy paid his rent because the word "yes" has 3 character?

    I;m sure none of this make sense to you guys but from my perspective I don't understand how to use a function with another and add variables into the mix to get where I want to be at the end. Constructing a function is easy. you jsut copy it from a manual. what do you do after though? what other function do you need to continue?
  10. #21
  11. Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jan 2004
    Location
    New Springfield, OH
    Posts
    1,175
    Rep Power
    1469
    You are asking all the right questions, but in all the wrong context.

    However, this is good:
    Originally Posted by jaad
    The strlen() function returns the length of a string, in characters.

    The example below returns the length of the string "Hello world!":

    PHP Code:
    <?php
    echo strlen("Hello world!");
    ?>
    Result: 12

    Questions:

    1-Why would I ever need to know how many letters there is in a string?

    2- why does the function measures the content by characters? why not use inches or centimeter instead?

    3- Why put "hello world" between braces?

    4- Why put double quotes when everywhere else people are using single quote marks

    5- then I have an answer: 12
    how is that relevant or why should I use the number (12) in a form or in a procedure where I am trying to find out if a field has a value = to what a user has inputted in a form? is this something that will help me figure out if a tenant paid his rent last month? like as in if(strlen() = 3) then yes the guy paid his rent because the word "yes" has 3 character?
    1. What if you wanted to validate a user's input as a valid 5-digit zip code? Or a ten-digit phone number? Or a password that must be at least 8 characters long?

    It's also good for checking the length of a string before attempting to write it to a database field. (You'll just get an error if it won't fit.)

    2. Because it's the only metric with which to measure a string. String size in terms of inches would be relative to the output device, not the string contents. (Although I sense a bit of sarcasm with this question.)

    3. Because it's a string. The Hello World phrase has become somewhat ubiquitous with sample nonsense code samples.

    4. Good question. In short, either one works. PHP allows both single and double quotes as string delimiters. However, it treats them differently. Strings inside of double quotes are parsed before they are used. A good question for explanation later once you start using variables.

    5. In short, you shouldn't use the strlen() function to check if a variable is equal to a user-submitted value. It's the wrong tool for that particular job.
    Don't like me? Click it.

    Scripting problems? Windows questions? Ask the Windows Guru!

    Stay up to date with all of my latest content. Follow me on Twitter!

    Help us help you! Post your exact error message with these easy tips!
  12. #22
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2013
    Posts
    33
    Rep Power
    1

    thanks for answering my questions


    4. Good question. In short, either one works. PHP allows both single and double quotes as string delimiters. However, it treats them differently. Strings inside of double quotes are parsed before they are used. A good question for explanation later once you start using variables.

    That is great stuff! thanks I just read about that and learned how to escape " ' " with a "\" while writing in a string. this alone solves about 20 days of frustration at trying to figure out why I kept getting errors. I am fairly tenacious. when I am faced with a challenge I am hard headed. I keep trying to change things around until I get it right. But this " " and ' ' business really took a lot of my life lol.

    here is another question they dont tell you about in the book

    PHP Code:
    <?php
    $a 
    1$b 0;
    echo (
    $a AND $b) . "<br />";
    echo (
    $a or $b) . "<br />";
    echo (
    $a XOR $b) . "<br />";
    echo !
    $a "<br />";
    ?>
    I tried removing the period at the end and it makes an error. what is the period used for in this function? They explain everything about the function except why they write it the way they did and for me this is the whole idea of the function.
  14. #23
  15. Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jan 2004
    Location
    New Springfield, OH
    Posts
    1,175
    Rep Power
    1469
    The period is PHP's string concatenation operator. It takes the result of the binary operation (as a string) and then prepends it to a string.

    You could also say that it appends the "<br />".

    I chose to say it the first way because PHP is treating the binary output as a string because of the context in which it is used.

    Concatenate means to join two strings together. This might be a better example:
    PHP Code:
    <?php
    echo "this is " "all one string!";
    echo 
    "You can even " 'mix quotes!';
    ?>
    Last edited by Nilpo; December 5th, 2013 at 11:20 PM.
    Don't like me? Click it.

    Scripting problems? Windows questions? Ask the Windows Guru!

    Stay up to date with all of my latest content. Follow me on Twitter!

    Help us help you! Post your exact error message with these easy tips!
  16. #24
  17. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2013
    Posts
    33
    Rep Power
    1
    Originally Posted by Nilpo

    Concatenate means to join two strings together. This might be a better example:
    PHP Code:
    <?php
    echo "this is " "all one string!";
    echo 
    "You can even " 'mix quotes!';
    ?>
    that is very interesting... but why would you want to concatenate? can't you simply use a break line? and continue down the echos? or the echos wont work because only teh first one will get answered and the puck stop there type of thing? so if I want to write a function and want to keep it going with other syntax with other evaluations I just have to keep inserting "." in between each function, is that how it works?

    Here is another example that they show in the book bu it doesn't work(3/4 of their example dont work when I put them in teh browser by the way, and that is what I find frustrating with these How To books. half the stuff they tell you doesn't work or they dont tell you about the important stuff like this one:

    PHP Code:
    <?php


    echo $fuel <= "Fill tank now" "There's enough fuel";

    ?>
    I tried building a gastank with a variable

    $gastank=2
    $Fuel=$gastank

    and moved it above and below the function and it doesnt' work. Why do you think that is?

    Also another important tid bit? where is the "if" statement? sometime you can use "if" and other time you don't have to? and what is the ":" about? does that replace the "if"? like having teh "if" in the middle of the sentence?

    lol you guys are probably thinking I'm really thick lol
    and by teh way if I talk funny it's because English is not my first language.

    and,

    here is another one?

    PHP Code:
    <?php
    $count 
    1;
    while (
    $count <= 5)
    {
    echo 
    "$count times 12 is " $count 12 "<br />";
    ++
    $count;
    }
    ?>
    I don't get this???? the way I am reading this function it tells me that $count was assigned the value 1
    then it say while $count<=5 keep counting? right?
    but then it shows the time table of 12 as a string but right after it say count 12 times and each time you count add another line. the way I read this I would get a time table that would count 12 time +1 at each time you loop around. Why am I not getting 24 rows?

    then I tried something else. I removed the "<" in front of =5
    the loop went wild never stopping. isn't supposed to stop at 5 since it say count 5 times?
  18. #25
  19. Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jan 2004
    Location
    New Springfield, OH
    Posts
    1,175
    Rep Power
    1469
    Originally Posted by jaad
    that is very interesting... so if I want to write a function and want to keep it going with other syntax with other evaluations I just have to keep inserting "." in between each function, is that how it works?
    Exactly. It's also helpful when construction a string with variables.
    PHP Code:
    <?php
    $name 
    'Frank';

    echo 
    'Hello, ' $name '. Today is ' date(l);

    // returns:
    //       Hello, Frank. Today is Friday

    // Using double quotes ;-)
    //    PHP will parse the variable first!
    echo "Hello, $name. Today is " date(l);


    ?>

    Originally Posted by jaad
    Here is another example that they show in the book bu it doesn't work
    PHP Code:
    <?php


    echo $fuel <= "Fill tank now" "There's enough fuel";

    ?>
    It does work, but it's not quite a complete example. They are just illustrating a point. Assuming 1 is a full tank of gas, then .5 would be only a half a tank of gas. This code says "if $fuel is less than or equal to 1, echo 'Fill tank now', otherwise echo 'There's enough fuel'. (It should probably just use <, not <=)

    Originally Posted by jaad
    I tried building a gastank with a variable

    $gastank=2
    $Fuel=$gastank

    and moved it above and below the function and it doesnt' work. Why do you think that is?
    Variable names are case sensitive. Use a lowercase f. $fuel is not the same as $Fuel
    Originally Posted by jaad
    Also another important tid bit? where is the "if" statement? sometime you can use "if" and other time you don't have to? and what is the ":" about? does that replace the "if"? like having teh "if" in the middle of the sentence?
    This part gets a little complicated. It's a more advanced technique. The ? is called the Ternary Operator. It is used to assign a value based on a condition. It looks like this:

    $result = (condition) ? value1 : value2;

    It reads like this:

    If the condition evaluates to true, assign value1 to result, otherwise (if the condition evaluates to false) assign value 2 to $result.

    The Ternary Operator is used to make quick assignments based upon a condition. A sample here will probably help more.
    PHP Code:
    <?php

    // Let's assume we're trying to determine if it's AM or PM based on the current time.
    //PHP has functions for this but let's assume it didn't.
    $currentHour date("G");   // this returns 0 - 23, based on the current time.

    // This Ternary statement...
    $result = ($currentHour <= 11) ? "AM" "PM";

    // ...is the same as this...
    if ($currentHour <= 11) {
        
    $result "AM";
    } else {
        
    $result "PM";
    }

    ?>
    And your English is not bad at all.
    Don't like me? Click it.

    Scripting problems? Windows questions? Ask the Windows Guru!

    Stay up to date with all of my latest content. Follow me on Twitter!

    Help us help you! Post your exact error message with these easy tips!
  20. #26
  21. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2013
    Posts
    33
    Rep Power
    1
    Amazing! Thank you so much for taking the time to write this up for me. I really have no words to describe how I appreciate you doing this for me. I am going to try and work on this today. I am on holiday until next Wednesday and so far I have spent my whole holiday sitting in front of hte computer trying to learn. I think I reach a point where I can start learning now.

    I am going to manipulate the function in various ways until it finally clicks in my head. Right now it still doesn't make any sense but it will if I keep testing how each piece interact with the other. I am also going to try and readjust my attitude because I think I feel a bit resentful about feeling like a dumb ***.

    Before I go though, I am really curious about the reason why the function of the table of 12 went wild when I removed the "<" in front of the "=" ? Can't you just say to a While Loop- stop when it equals let say 5? does it have to be <=5 and can't be just =5?
  22. #27
  23. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,911
    Rep Power
    1045
    Originally Posted by jaad
    Before I go though, I am really curious about the reason why the function of the table of 12 went wild when I removed the "<" in front of the "=" ? Can't you just say to a While Loop- stop when it equals let say 5? does it have to be <=5 and can't be just =5?
    A single equality sign is an assignment, not an equality check. That would be a double equality sign: ==.

    The value of an assignment expression is the value of the right-hand side. So the expression $count = 5 evaluates to the number 5. And since this is considered a "truthy" value, the loop condition is always true, making the loop run forever.

    PHP does not have an until loop, so you can't tell it to run until a certain condition is true. You have to express this with a while loop: Run while the condition is false. In your case:

    PHP Code:
    while ($count != 5)
    {
        ...

    However, this would be a bad way of expression the logic, because this looks like the loop might continue at 6, 7, ... If you want "until 5", you should say exactly that: $count <= 5.

    This will also make your code robust. Otherwise, you'll get an infinite loop if the variable skips 5 due to a bug.
  24. #28
  25. Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jan 2004
    Location
    New Springfield, OH
    Posts
    1,175
    Rep Power
    1469
    Originally Posted by jaad
    Amazing! Thank you so much for taking the time to write this up for me. I really have no words to describe how I appreciate you doing this for me. I am going to try and work on this today. I am on holiday until next Wednesday and so far I have spent my whole holiday sitting in front of hte computer trying to learn. I think I reach a point where I can start learning now.
    You're very welcome.
    Originally Posted by jaad
    Before I go though, I am really curious about the reason why the function of the table of 12 went wild when I removed the "<" in front of the "=" ? Can't you just say to a While Loop- stop when it equals let say 5? does it have to be <=5 and can't be just =5?
    I think you're talking about this code:
    PHP Code:
    <?php 
    $count 
    1;
    while (
    $count <= 5)
    {
        echo 
    "$count times 12 is " $count 12 "<br />";
        ++
    $count;
    }
    ?>
    The while loop will continue to run "while" the condition evaluates to true.

    In other words, you are saying continue to loop "while $count is less than or equal to 5". Since count starts at 1 and increases by 1 for each iteration, it simply counts until it reaches 5 (based on the condition you specified above).

    After the first iteration, $count equals 2 which is still less than 5, and the loop continues. Once $count equals 6 (which is not less than or equal to 5), the loop stops.

    If you remove the < sign, you're now saying continue to loop "while $count = 5". Since it starts at 1, and it is incremented inside of the loop, $count is never equal to 5 and the code inside the loop never gets executed.

    [EDIT]I should have also explained that = is not a comparison operator as well. Thanks for pointing that out, Jacques.[/EDIT]
    Last edited by Nilpo; December 6th, 2013 at 10:29 AM.
    Don't like me? Click it.

    Scripting problems? Windows questions? Ask the Windows Guru!

    Stay up to date with all of my latest content. Follow me on Twitter!

    Help us help you! Post your exact error message with these easy tips!
  26. #29
  27. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,911
    Rep Power
    1045
    Originally Posted by Nilpo
    Since it starts at 1, and it is incremented inside of the loop, $count is never equal to 5 and the code inside the loop never gets executed.
    No. Repeating my post from above: $count = 5 is an assignment, which causes an infinite loop.

    // Has been settled.

    Comments on this post

    • Nilpo agrees
  28. #30
  29. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2013
    Posts
    33
    Rep Power
    1
    Originally Posted by Jacques1
    No. Repeating my post from above: $count = 5 is an assignment, which causes an infinite loop.

    // Has been settled.
    Now I get it!

    so in other words, what would work would be to write it like this: (==5) right? Amazing! I'm finally learning something. thank you

IMN logo majestic logo threadwatch logo seochat tools logo