Results 1 to 8 of 8

Thread: PHP/MySLQ Tutorials

  1. #1
    Join Date
    Apr 2008
    Posts
    38
    Thanks
    9
    Thanked 1 Time in 1 Post

    Question PHP/MySLQ Tutorials

    Anyone know a good tutorial? The one at http://www.w3schools.com/php/php_mysql_intro.asp is a little too complex.

  2. #2
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    http://www.php-mysql-tutorial.com is a good one.
    Hope this helps.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  3. #3
    Join Date
    Jan 2007
    Location
    The stage
    Posts
    568
    Thanks
    23
    Thanked 6 Times in 6 Posts

    Default

    I thought that one was good...
    I can give you a good tutorial on MySQL
    First getting stuff from the database you need a couple main parts...
    PHP Code:
    <?php
    $con 
    mysql_connect("host","username_of_database_admin","password_for_the_corresponding_username_of_the_administrator");
    if (!
    $con)
      {
      die(
    'Could not connect: ' mysql_error());
    //A basic line that says if the variable $con isn't correct it can't connect so it gives an error and kills the functions for the rest of the page...
      
    }

    mysql_select_db("database"$con);

    $result mysql_query("SELECT * FROM table WHERE row='$user'");
    /*When getting stuff using WHERE remeber these key rules:
    for numbers always do
    WHERE row=1
    for variables always do 
    WHERE row='$variable'
    for normal text ALWAYS do
    WHERE row='text'
    And it is case-sensitive
    --
    You also don't have to use where
    */
    while($row mysql_fetch_array($result))
      {
         
    // To get stuff from the row you will use this: $row['columnname']
    //Below is an example
    echo $row['time'];
    echo 
    $row['username'];
    //You can put if statements in here as well...
     
    if($row['username']=1){
        echo 
    $row['time'];
    }else{
    echo 
    "Rockonmetal Rules";
    }
    }
    //That second bracket is for the while function which gets the data from the database...
    ?>
    To put stuff in a database you should have MySQL... I had no luck with WAMP5 but you can try... It apparently works right out of the box... I'm the one exception...
    General Question:
    How much experience do you have with PHP and or MySQL?
    if so... another tutorial I sometimes use is:
    http://www.php-mysql-tutorial.com/
    W3 schools is helpful and resourceful... Though the best is www.php.net (official site of php) it has all the functions ever made for php... (I wonder why? but its a very good site)

  4. #4
    Join Date
    Apr 2008
    Posts
    38
    Thanks
    9
    Thanked 1 Time in 1 Post

    Default

    I have MySQL on my web host. Is there a tutorial for that?

  5. #5
    Join Date
    Jan 2007
    Location
    The stage
    Posts
    568
    Thanks
    23
    Thanked 6 Times in 6 Posts

    Default

    I'll just explain everything since its easier to do that cuz I learned myself.
    First you have to find mysql manager... You need add a database (call it what ever you want) to make sure phpmyadmin is on your hosting service...
    Once you make a database head to phpmyadmin. Then click on your new database on the left frame. You should get a page in the main (right) showing you have no tables in the database. Below that message you should see a form which says make a new table. Give it a name (avoid typing spaces at all costs) and add a rough number of how many "fields" you'll have in the database. It should bring you to a form with a bunch of name things:
    Heres the best way to do a simple user database:
    Field 1 name "id" type "int" extras "auto-increment" set it as a primary key
    Field 2 name "user" type "text" extras "none"
    Field 3 name "password" type "text" extras "none"
    Field 4 name "email" type "text" extras "none"
    leave everything else blank or how it was if I don't specify what to do with it...
    To insert stuff into the database there should be a tab on the browse, structure, export, opperations, drop (delete), and insert. (Might not be the exact order).
    Hope this helps

  6. #6
    Join Date
    Apr 2008
    Posts
    38
    Thanks
    9
    Thanked 1 Time in 1 Post

    Lightbulb

    I finished doing the code. The form that submits it has four fields: username, password, title and post. Its method is POST. Please give feedback:
    <html>

    <head>

    <title></title>

    </head>

    <body>
    <a href="http://lightbulbproductions.net">Back</a>
    <?php
    $username = $_POST["username"];
    $pass = $_POST["pass"];
    $usernames = array("user1", "user2");
    $passwords = array("pass1", "pass2");
    $title = $_POST["title"];
    $post = $_POST["post"];
    for ($login = 0; $login < 2; $login++)
    {
    if ($username == $usernames[$login] && $pass == $passwords[$login])
    {
    sql();
    break;
    }

    }
    function sql() {
    $connect = @mysql_connect("http://www.lightbulbproductions.net/php/", "admin", "password");
    if (!$connect) {
    die( "<P>Unable to connect to the " .
    "database server at this time.</P>" );
    exit();
    } else {
    mysql_query("INSERT INTO forum (user, title, post)
    VALUES ($username, $title, $post)");

    }
    mysql_close($connect);
    }
    ?>
    </body>

    </html>
    PS. If I wanted to find the length of an array named arrayExample in JavaScript, you could find it with arrayExample.length. Is there a PHP counterpart?

  7. #7
    Join Date
    Jan 2007
    Location
    The stage
    Posts
    568
    Thanks
    23
    Thanked 6 Times in 6 Posts

    Default

    Looks good...
    You can find the length of a string by doing this line of code in php:
    Code:
    <?php
    echo strlen("Hello World");
    //Or with variables:
    $variable = "Don't forget to thank!";
    echo strlen($variable);
    
    ?>
    This one will tell you how many items there are in an array...
    Code:
    <?php
    $people = array("Peter", "Joe", "Glenn", "Cleveland");
    $result = sizeof($people);
    
    echo $result;
    ?>
    I don't know if the strlen function will work with arrays... You should try it...
    Looks like you picked up php really quickly.
    For references to all the php functions you can go to w3 || php.net download manual || here

  8. #8
    Join Date
    Mar 2008
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I found this PHP tutorial download to be a good and starting place if you are using dreamweaver.

    http://www.sawmac.com/missing/dw8/

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
  •