Start with PHP, need small example scripts

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • asedt
    New Member
    • Jun 2008
    • 130

    Start with PHP, need small example scripts

    Just installed EasyPHP, got inspired from the other thread. I'm good at HTML/CSS/JavaScript/Programming but haven't touched PHP that much.

    So where do I begin, I want to make some more advanced pages later with login/blog/forum/chan features but start with some simple basic.

    I have worked some with databases in phpMyAdmin and think i understand databases quite good.

    If anyone can give me some very small scripts/guidelines to begin with i can learn some from those.
  • asedt
    New Member
    • Jun 2008
    • 130

    #2
    Things i want to learn more about:

    1. Create databases in phpMyAdmin.

    2. Use databases in php code.
    (http://www.php-mysql-tutorial.com/connect-to-mysql-using-php.php)

    3. Take input from forms correctly, with security checks and stuff.

    4. Create login/account system (only for admin e.g. limited users). Encrypted passwords?


    Start with that, any help i like very much.

    Comment

    • Markus
      Recognized Expert Expert
      • Jun 2007
      • 6092

      #3
      Giving you 'scripts' wouldn't help you, I don't think. Do you know any PHP or are you just starting? If the former, take a look at these tutorial sites - it's what got me started.


      W3Schools offers free online tutorials, references and exercises in all the major languages of the web. Covering popular subjects like HTML, CSS, JavaScript, Python, SQL, Java, and many, many more.

      Comment

      • flydev
        New Member
        • Feb 2008
        • 33

        #4
        I'm a "beginner" myself, and i have to say those two sites really get the job done on explaining how things work. Good luck, I'm sure you will find that PHP is a very rewarding language.

        Comment

        • asedt
          New Member
          • Jun 2008
          • 130

          #5
          Originally posted by Markus
          Giving you 'scripts' wouldn't help you, I don't think. Do you know any PHP or are you just starting? If the former, take a look at these tutorial sites - it's what got me started.


          http://www.w3schools.com

          Thank you, i will go thou that tutorial, it feels like i know PHP, but i haven't written so much. I started long time ago but then i didn't do much more.

          Comment

          • Markus
            Recognized Expert Expert
            • Jun 2007
            • 6092

            #6
            Originally posted by asedt
            Thank you, i will go thou that tutorial, it feels like i know PHP, but i haven't written so much. I started long time ago but then i didn't do much more.
            Also, don't forget to check http://php.net for any references to functions, classes, etc.

            Comment

            • asedt
              New Member
              • Jun 2008
              • 130

              #7
              Code:
              <?php
              $dbhost = 'localhost';
              $dbuser = 'root';
              $dbpass = '';
              
              $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');
              
              $dbname = 'test';
              mysql_select_db($dbname);
              
              $result = mysql_query("INSERT INTO SimpleLog(Name, Text) VALUES('Nam', 'ext')")
                  or die("error...");
              
              ?>
              Works :) yey

              Comment

              • asedt
                New Member
                • Jun 2008
                • 130

                #8
                1-3 almost done, need help with point 4..

                Comment

                • asedt
                  New Member
                  • Jun 2008
                  • 130

                  #9
                  This is my try on trying to do a guest book, but its far from good. :(


                  First I create a table("SimpleLo g") in the test db in sqlMyAdmin, I create it with two columns one for name(VARCHAR 50) and one for text(VARCHAR 500). (I guess this is a very bad designed database, you can give me some hints on how to improve it).


                  Then I do two php files, one with the form and showing of the guest book, and one that the form calls to add entrys to the database.

                  Form php file(board.php) :
                  Code:
                  <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
                     "http://www.w3.org/TR/html4/strict.dtd">
                  
                  <html>
                  
                  <head>
                     <title>PHP MBoard</title>
                  </head>
                  
                  <body>
                  
                     <form action="addM.php" method="post">
                        <p>
                           <input type="text" name="name" value="Enter nick"><br>
                           <textarea name="comment" rows="5" cols="60">Enter message</textarea><br>
                           <input type="submit" name="Send" value="Send">
                           <input type="reset" name="Clear" value="Clear">
                        </p>
                     </form> 
                  
                  <?php
                  mysql_connect("localhost", "root", "") or die(mysql_error());
                  mysql_select_db("test") or die(mysql_error());
                  
                  $result = mysql_query("SELECT * FROM SimpleLog") or die(mysql_error());  
                  
                  while($row = mysql_fetch_array($result)) {
                  	echo "<div class='name'>";
                  	echo $row['Name'];
                  	echo "</div>\n";
                  
                  	echo "<div class='text'>";
                  	echo $row['Text'];
                  	echo "</div>";
                  	echo "<hr>\n\n";
                  }
                  ?>
                  
                  </body>
                  </html>
                  And the add to database(addM.p hp):

                  Code:
                  <?php
                  	if (isset($_POST['name']))
                  		$name = addslashes($_POST['name']);
                  	else
                  	{
                  		echo "Name missing.";
                  		exit();
                  	}
                  
                  	if (isset($_POST['comment']))
                  		$comment = addslashes($_POST['comment']);
                  	else
                  	{
                  		echo "Comment missing.";
                  		exit();
                  	}
                  
                  $dbhost = 'localhost';
                  $dbuser = 'root';
                  $dbpass = '';
                  
                  $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');
                  
                  $dbname = 'test';
                  mysql_select_db($dbname);
                  
                  $result = mysql_query("INSERT INTO SimpleLog(Name, Text) VALUES('$name', '$comment')")
                      or die(mysql_error());  
                  
                  echo " <a href='board.php'>Go back to notice board</a>";
                  ?>
                  Things I want to add: Client side javascript controls. Some spam control of some kind.

                  Is my code crap or do you think I'm on the right track?

                  Comment

                  • asedt
                    New Member
                    • Jun 2008
                    • 130

                    #10
                    Oh now i did find some nice things among the howtos, I will read some of them now.

                    Tip for you other PHP beginners.

                    Comment

                    Working...