SitePoint Sponsor

User Tag List

Page 3 of 4 FirstFirst 1234 LastLast
Results 51 to 75 of 76

Thread: Php for kids

  1. #51
    SitePoint Addict bbparis's Avatar
    Join Date
    Aug 2008
    Posts
    323
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by BJ Duncan View Post
    A little late on the thread, but a fantastic resource site for video php is PHP Video Tutorials. The creator of the site is an Aussie guy by the name of LeighMac. This site is absolutely fantastic and he has free lessons (no catches). Highly recommended.
    Thanks BJ Duncan,

    Really thanks for your help, I saved the link and I will check it later, between time and time, I relax from lynda.com courses by watching another free videos.

    Again thanks.

  2. #52
    SitePoint Evangelist BJ Duncan's Avatar
    Join Date
    Jun 2007
    Location
    Bowen Mountain, NSW
    Posts
    490
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by bbparis View Post
    Hi for all, a new question please :

    How can I check the data in a form before post it to the database ??

    there is a simple way to check if the form still empty and show message says ( form empty, please write something ) ??
    You can check the data by placing it in a condition:
    PHP Code:
    <?php
    // place all POST values into an array and call them when you need them.
    $params $_POST;

    if(empty(
    $params['username'])) {
       
    $empty TRUE;
    }

    if(empty(
    $params['password'])) {
       
    $empty TRUE;
    }

    // the empty() function tests to see if the 
    //variable within holds any content value.

    // then you can do a test for it all E.G
    if ($empty) {
       
    // Do what ever you want here then 
       // redirect the user back to the signup page
    }
    // this is basically saying that
    // if the variable $empty DOES hold a value (which it will if any of the $params are empty) then you can redirect with a message
    ?>
    Hope this helps a little...
    Regards,
    BJ Duncan

  3. #53
    SitePoint Addict bbparis's Avatar
    Join Date
    Aug 2008
    Posts
    323
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks BJ Ducan for your help, I will try this script and get back to you.

  4. #54
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Trim() your input before checking the length - that way:
    "hello " would count as 5 letters
    " " would be 0 letters
    " Hello World " would count as 11 letters.
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  5. #55
    SitePoint Addict bbparis's Avatar
    Join Date
    Aug 2008
    Posts
    323
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by arkinstall View Post
    Trim() your input before checking the length - that way:
    "hello " would count as 5 letters
    " " would be 0 letters
    " Hello World " would count as 11 letters.
    hello arkinstall,

    I'm really sorry, but what you mean when you say Trim() ??
    do you have an example ?

  6. #56
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    <?php
    $_POST
    ['username'] = trim($_POST['username']);
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  7. #57
    SitePoint Evangelist BJ Duncan's Avatar
    Join Date
    Jun 2007
    Location
    Bowen Mountain, NSW
    Posts
    490
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by bbparis View Post
    hello arkinstall,

    I'm really sorry, but what you mean when you say Trim() ??
    do you have an example ?
    trim() is an in-built function.
    PHP Code:
    <?php

    $value 
    " Hello";

    $newValue trim($value);

    echo 
    $newValue;
    // output would be "Hello"

    // Notice that the space is now missing from the "Hello"
    To learn more on in-built functions visit the php.net site.

    PHP has many many many in-built functions that are very useful.
    Regards,
    BJ Duncan

  8. #58
    SitePoint Addict bbparis's Avatar
    Join Date
    Aug 2008
    Posts
    323
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Really I appreciate your help arkinstall and BI Ducan, please the script below and let me know if I used trim() in-built function in the write way :

    PHP Code:
    <?php

    include("config.php");

    function 
    escape($value){
        if (
    get_magic_quotes_gpc()) {
            
    $value stripslashes($value);
        }
        
        
    $value mysql_real_escape_string($value);
        return 
    $value;
    }

    // connect to MySQL server
    $connect mysql_connect($server,$db_user,$db_pass) or die(" not possible to connect the server".mysql_error());

    // select the database
    mysql_select_db($database) or die("cannot select the database".mysql_error());

    // Wash input data.
    $_POST['linkname'] = trim($_POST['linkname']);
    $_POST['link'] = trim($_POST['link']);

    $name escape($_POST['linkname']);
    $link escape($_POST['link']);

    // check if the link already submited 
    $check "SELECT ID FROM $table WHERE link = '".$link."';";

    $qry mysql_query($check) or die (" Could not match data because".mysql_error());

    $num_rows mysql_num_rows($qry);

    if ( 
    $num_rows != ){
        echo 
    " this link is already in the database";
        
    //exit;
    } else {
        
    // insert data
        
    $insert=mysql_query("INSERT INTO $table VALUES ('NULL','".$name."','".$link."');") or die("could not insert data because".mysql_error());
        echo 
    " thanks, your link has been added successfully";
    }

    ?>

  9. #59
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    You're doing it right, but may I suggest using it in the escape function, if both values are going through it anyway?
    PHP Code:
    <?php
    include("config.php"); 
    function 
    escape($value){ 
        if (
    get_magic_quotes_gpc()) { 
            
    $value stripslashes($value); 
        }
        
    $value mysql_real_escape_string($value); 
        return 
    trim($value);


    // connect to MySQL server 
    $connect mysql_connect($server,$db_user,$db_pass) or die(" not possible to connect the server".mysql_error()); 

    // select the database 
    mysql_select_db($database) or die("cannot select the database".mysql_error()); 

    $name escape($_POST['linkname']); 
    $link escape($_POST['link']);
    ?>
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  10. #60
    SitePoint Evangelist BJ Duncan's Avatar
    Join Date
    Jun 2007
    Location
    Bowen Mountain, NSW
    Posts
    490
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Spot on agree with arkinstall.
    Last edited by BJ Duncan; Aug 28, 2008 at 08:20.
    Regards,
    BJ Duncan

  11. #61
    SitePoint Addict bbparis's Avatar
    Join Date
    Aug 2008
    Posts
    323
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by arkinstall View Post
    You're doing it right, but may I suggest using it in the escape function, if both values are going through it anyway?

    thanks again, but just to learn, why in the escape function ?? and please if you can just give me a simple explication about escape function, who it is working in my script ( example, when someone try to add a link, what it will do exactly ? )

    sorry to bother you with my question, but i'm trying my best to learn, also not all time easy to understand on php.net

  12. #62
    SitePoint Evangelist BJ Duncan's Avatar
    Join Date
    Jun 2007
    Location
    Bowen Mountain, NSW
    Posts
    490
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by bbparis View Post
    thanks again, but just to learn, why in the escape function ?? and please if you can just give me a simple explication about escape function, who it is working in my script ( example, when someone try to add a link, what it will do exactly ? )

    sorry to bother you with my question, but i'm trying my best to learn, also not all time easy to understand on php.net
    You are placing it within the escape function because the escape function is handling the data that is inputted into the form and is going to be submitted.

    PHP Code:
    <?php 
    include("config.php"); 
    // this function sits here and waits to be called.
    function escape($value){     
       if (
    get_magic_quotes_gpc()) {         
          
    $value stripslashes($value);     
       }     
       
    $value mysql_real_escape_string($value);     
       return 
    trim($value); 
    }  


    // connect to MySQL server 
    $connect mysql_connect($server,$db_user,$db_pass) or die(" not possible to connect the server".mysql_error());  

    // select the database 
    mysql_select_db($database) or die("cannot select the database".mysql_error());  
    // here is where you are calling or executing the function
    // that was created at the top of the script.

    $name escape($_POST['linkname']); 
    // you are creating a variable by the name of '$name'. 
    // Within this variable, you are now placing the value of $_POST['linkname']
    // in it. However, because you are calling the function escape()
    // then the $_POST['linkname'] substitues the $value variable in the function.

    // So basically this is what you are doing:
    $name $_POST['linkname'];
    if (
    get_magic_quotes_gpc()) { 
       
    $name stripslashes($name);     
    }     
    $name mysql_real_escape_string($name);  

    echo 
    $name;
    // the output here will give you the same result as the top part,
    // however, the difference is that you would have to type all
    // this out again for every field that you are submitting.

    // So then you would also have to have:
    $link $_POST['link'];
    if (
    get_magic_quotes_gpc()) { 
       
    $link stripslashes($link);     
    }     
    $link mysql_real_escape_string($link);  
    echo 
    $link;

    // now imagine having 5 or more fields that you wanted cleaned!!!
    // So it is much easier and more readable to create a function
    // as demonstrated at the top, so then to use the same function, 
    // it only has to be called by it's function name.


    ?>
    Hope this helps.
    Regards,
    BJ Duncan

  13. #63
    SitePoint Addict bbparis's Avatar
    Join Date
    Aug 2008
    Posts
    323
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    arkinstall and BI Ducan, again thanks for you and for all who tried to help me.

    I'm sooo happy, the script works now without problem, please check it and test it also ( invitation for all members and visitors ):

    http://www.beginfromhere.com/php/addyourlink/

    and let me know is still has any bug.

    my next step will be Validate link, so no link will appear in the page before validation, but hohoooo wait wait, I have to learn all what is happened till now, before the things will be hard for me. so in case I will have any question, I will ask you my php friends.

    Best regards,
    bbparis

  14. #64
    SitePoint Evangelist BJ Duncan's Avatar
    Join Date
    Jun 2007
    Location
    Bowen Mountain, NSW
    Posts
    490
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by bbparis View Post
    arkinstall and BI Ducan, again thanks for you and for all who tried to help me.
    No dramas, no matter who you are, we have ALL been exactly where you are so ask away.

    Also, just to let you know, it's BJ, not BI
    Regards,
    BJ Duncan

  15. #65
    SitePoint Addict bbparis's Avatar
    Join Date
    Aug 2008
    Posts
    323
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by BJ Duncan View Post
    No dramas, no matter who you are, we have ALL been exactly where you are so ask away.

    Also, just to let you know, it's BJ, not BI
    First sorry about J, and sure I'm soo happy to be in the right place.

    again thanks for you and all other friends on Sitepoint.com

  16. #66
    SitePoint Guru themightystephen's Avatar
    Join Date
    Mar 2005
    Location
    England
    Posts
    608
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just in case it's not clear:

    trim() is used on a string to remove all spaces on both ends of the string. For example "hey dude " becomes "hey dude" when trim() is applied to it - like this, trim("hey dude "). Most the time you would be trimming a variable - like this, trim($myString).

    escape() is used to escape data submitted by the user. Escaping data is used for security. A malicious user may provide a sequence of characters that are designed to alter the SQL that the database is queried with. This is called SQL injection. Escaping the data therefore is a counter-measure taken to stop SQL injection.
    Get your heelys now at flywalk.co.uk - But what are heelys?
    Heelys are simply shoes with wheels in the heels!

    Flywalk.co.uk - The UK Heelys Retailer

  17. #67
    SitePoint Addict bbparis's Avatar
    Join Date
    Aug 2008
    Posts
    323
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by themightystephen View Post
    Just in case it's not clear:

    trim() is used on a string to remove all spaces on both ends of the string. For example "hey dude " becomes "hey dude" when trim() is applied to it - like this, trim("hey dude "). Most the time you would be trimming a variable - like this, trim($myString).

    escape() is used to escape data submitted by the user. Escaping data is used for security. A malicious user may provide a sequence of characters that are designed to alter the SQL that the database is queried with. This is called SQL injection. Escaping the data therefore is a counter-measure taken to stop SQL injection.
    Thanks you hemightystephen, really I appreciate your help, you are so nice to try to make it more clear for me and all who will read your thread.

    I'm learning now the code again and again to understand more and more.

  18. #68
    SitePoint Evangelist BJ Duncan's Avatar
    Join Date
    Jun 2007
    Location
    Bowen Mountain, NSW
    Posts
    490
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't mean to confuse you more however, just to clarify further upon themightystephen's reply,

    The trim() function is a PHP in-built function. This function will run anytime you place it within your php code.

    The escape() function is a user-defined function that is in the above examples.

    themightystephen is correct with the definition of:
    Quote Originally Posted by themightystephen View Post
    is used to escape data submitted by the user. Escaping data is used for security. A malicious user may provide a sequence of characters that are designed to alter the SQL that the database is queried with. This is called SQL injection. Escaping the data therefore is a counter-measure taken to stop SQL injection.
    but should be noted that this is in reference to the other in-built function mysql_real_escape_string() and not the user defined function of escape().

    The difference with an in-built function and a user defined function is that an in-built function can be called at anytime throughout the php code without defining what it does anywhere in your own code, where as a user defined function can be called anywhere in the code but the function must be defined within the code. (Generally at the top of the script).
    Regards,
    BJ Duncan

  19. #69
    SitePoint Guru themightystephen's Avatar
    Join Date
    Mar 2005
    Location
    England
    Posts
    608
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah, he's right.
    Get your heelys now at flywalk.co.uk - But what are heelys?
    Heelys are simply shoes with wheels in the heels!

    Flywalk.co.uk - The UK Heelys Retailer

  20. #70
    SitePoint Addict bbparis's Avatar
    Join Date
    Aug 2008
    Posts
    323
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi again,

    A friend visited my first script, that I done till now with your help, and asked me an important question, what if I have more than 100 links or 200 and more, and advised me to learn about PHP Pagination, so I hope you can give me an idea about it ? and what is the simple way to learn about it.

    Best regards to all.

  21. #71
    SitePoint Addict bbparis's Avatar
    Join Date
    Aug 2008
    Posts
    323
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by BJ Duncan View Post
    I don't mean to confuse you more however, just to clarify further upon themightystephen's reply,

    The trim() function is a PHP in-built function. This function will run anytime you place it within your php code.

    The escape() function is a user-defined function that is in the above examples.

    themightystephen is correct with the definition of:

    but should be noted that this is in reference to the other in-built function mysql_real_escape_string() and not the user defined function of escape().

    The difference with an in-built function and a user defined function is that an in-built function can be called at anytime throughout the php code without defining what it does anywhere in your own code, where as a user defined function can be called anywhere in the code but the function must be defined within the code. (Generally at the top of the script).

    ohhh , do you know that I like to learn more and more, and as I understand, each time we want to use escape function, we have to write the function above like the following :

    PHP Code:
    function escape($value){      
       if (
    get_magic_quotes_gpc()) {          
          
    $value stripslashes($value);      
       }      
       
    $value mysql_real_escape_string($value);      
       return 
    trim($value); 

    because it's not including in php in-built codes. to be honest, till now, I don't know what ( mysql_real_escape_string() ) will do exactly, I read the explanation from themightystephen about it, but ... I don't know... maybe I have to use it like that !?

  22. #72
    SitePoint Evangelist BJ Duncan's Avatar
    Join Date
    Jun 2007
    Location
    Bowen Mountain, NSW
    Posts
    490
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey bbParis,

    Firstly, its great to hear from someone that is very enthusiastic about learning PHP. I could only imagine that you just want to know it all so you can do it all now. I was also like that. I just wanted to know everything.

    You are approach to learning the language is very `gunho`. May I make a suggestion to you with learning PHP. Learn the basics first. Understand all the terminology, know what all the definitions are. Know the difference between boolean, string, variable, integar, arrays. What a funcion is. How to use a function. Although you say you wanted to view videos on learning PHP, I highly recommend getting How to build a database website in PHP by Kevin Yank.

    As much as I (and others) don't mind answering questions, you would be better off to take out a bit of time from looking online and forums etc to read this book. It will give you strong fondation and also great direction in your journey to learning PHP.

    Just a suggestion mate.
    Regards,
    BJ Duncan

  23. #73
    SitePoint Addict bbparis's Avatar
    Join Date
    Aug 2008
    Posts
    323
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Good morning BJ Duncan,

    I appreciate your advice and I will do my best to learn it as soon as I get it, also I'm doing my best to learn by video, now I'm watching LYNDA video courses. I prefer to learn by examples, because I heat the books/videos that will explain just how the functions work, and I prefer to learn about functions and other things by examples, tutorial and like that.

    again thanks for you and for all my forum friends, for your help and your advices.

  24. #74
    SitePoint Addict bbparis's Avatar
    Join Date
    Aug 2008
    Posts
    323
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    by the way, I forgot to say something, do you know that I build www.beginfromhere.com because I believe that by this way I can learn by experience, for example when I build Add Your Link idea, with your help and the help of other nice people like you in this forum, I learned something very interesting about the way to protect data before sending it to the database, and like this things, make the learning way more attractive, and funny.

  25. #75
    SitePoint Evangelist BJ Duncan's Avatar
    Join Date
    Jun 2007
    Location
    Bowen Mountain, NSW
    Posts
    490
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well you definately have started on the right foot by joining this forum.

    Have you had a chance to visit http://www.phpvideotutorials.com?
    Regards,
    BJ Duncan


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •