By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,746 Members | 1,928 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,746 IT Pros & Developers. It's quick & easy.

Start with PHP, need small example scripts

100+
P: 125
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.
Oct 19 '08 #1
Share this Question
Share on Google+
9 Replies


100+
P: 125
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.
Oct 19 '08 #2

Markus
Expert 5K+
P: 6,050
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.tizag.com/
http://www.w3schools.com
Oct 19 '08 #3

P: 33
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.
Oct 19 '08 #4

100+
P: 125
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.tizag.com/
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.
Oct 19 '08 #5

Markus
Expert 5K+
P: 6,050
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.
Oct 19 '08 #6

100+
P: 125
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $dbhost = 'localhost';
  3. $dbuser = 'root';
  4. $dbpass = '';
  5.  
  6. $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');
  7.  
  8. $dbname = 'test';
  9. mysql_select_db($dbname);
  10.  
  11. $result = mysql_query("INSERT INTO SimpleLog(Name, Text) VALUES('Nam', 'ext')")
  12.     or die("error...");
  13.  
  14. ?>
Works :) yey
Oct 19 '08 #7

100+
P: 125
1-3 almost done, need help with point 4..
Oct 19 '08 #8

100+
P: 125
This is my try on trying to do a guest book, but its far from good. :(


First I create a table("SimpleLog") 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):
Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
  2.    "http://www.w3.org/TR/html4/strict.dtd">
  3.  
  4. <html>
  5.  
  6. <head>
  7.    <title>PHP MBoard</title>
  8. </head>
  9.  
  10. <body>
  11.  
  12.    <form action="addM.php" method="post">
  13.       <p>
  14.          <input type="text" name="name" value="Enter nick"><br>
  15.          <textarea name="comment" rows="5" cols="60">Enter message</textarea><br>
  16.          <input type="submit" name="Send" value="Send">
  17.          <input type="reset" name="Clear" value="Clear">
  18.       </p>
  19.    </form> 
  20.  
  21. <?php
  22. mysql_connect("localhost", "root", "") or die(mysql_error());
  23. mysql_select_db("test") or die(mysql_error());
  24.  
  25. $result = mysql_query("SELECT * FROM SimpleLog") or die(mysql_error());  
  26.  
  27. while($row = mysql_fetch_array($result)) {
  28.     echo "<div class='name'>";
  29.     echo $row['Name'];
  30.     echo "</div>\n";
  31.  
  32.     echo "<div class='text'>";
  33.     echo $row['Text'];
  34.     echo "</div>";
  35.     echo "<hr>\n\n";
  36. }
  37. ?>
  38.  
  39. </body>
  40. </html>
  41.  
And the add to database(addM.php):

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.     if (isset($_POST['name']))
  3.         $name = addslashes($_POST['name']);
  4.     else
  5.     {
  6.         echo "Name missing.";
  7.         exit();
  8.     }
  9.  
  10.     if (isset($_POST['comment']))
  11.         $comment = addslashes($_POST['comment']);
  12.     else
  13.     {
  14.         echo "Comment missing.";
  15.         exit();
  16.     }
  17.  
  18. $dbhost = 'localhost';
  19. $dbuser = 'root';
  20. $dbpass = '';
  21.  
  22. $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');
  23.  
  24. $dbname = 'test';
  25. mysql_select_db($dbname);
  26.  
  27. $result = mysql_query("INSERT INTO SimpleLog(Name, Text) VALUES('$name', '$comment')")
  28.     or die(mysql_error());  
  29.  
  30. echo " <a href='board.php'>Go back to notice board</a>";
  31. ?>
  32.  
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?
Oct 19 '08 #9

100+
P: 125
Oh now i did find some nice things among the howtos, I will read some of them now.

Tip for you other PHP beginners.
Oct 19 '08 #10

Post your reply

Sign in to post your reply or Sign up for a free account.