Home / Archives /

php mysql tutorial

php mysql tutorial / 4 posts found

PHP/MySQL Tutorial Part 4 – Retrieve Data

by Leo
Comments are off for this post.
To retrieve after inserting them (see older post PHP/MySQL Tutorial Part 3), simply select the record from the desired table.  Use this SQL statement: SELECT * FROM table_name; Eg. $result = mysql_query("SELECT * FROM tablename"); $row = mysql_fetch_assoc($result); while($row = mysql_fetch_assoc($result)) { echo $row['name']; echo "-"; echo $row['email']; } This would display: Terence - terence@someemail.com Johnny - johnny@otheremail.com You can control the results with varying the statement. Eg. SELECT name FROM tablename - retreives the name column only SELECT * FROM tablename ORDER BY id DESC - shows last record first SELECT * FROM tablename LIMIT 5 - shows the first [...]

PHP/MySQL Tutorial Part 3 – Insert Records

by Leo
Comments are off for this post.
After connecting to the database (see older post PHP/MySQL Tutorial Part 2), the next step would probably be inserting data into it. It is actually pretty simple.  The steps are: 1. Connect to the database 2. Select the right table 3. put the data in You would need to setup a form on your website.  Let's start with a simple one which contains name and email addresses only.  Use "POST" and when the form is submitted, send the data to "insert.php". And in insert.php, first use "POST" to gather the data, then use the following SQL statement: $sql = "INSERT INTO [...]

PHP/MySQL Tutorial Part 2 – Connect to Database

by Leo
Comments are off for this post.
After you have verified that your server supports PHP (see older post PHP/MySQL Tutorial Part 1), you can go ahead to create a database, and connect to it.  Usually Linux server packages comes with tools like cPanel, where you can create a database, a user and a password on a web interface.  It is relatively simple, and hence we are not going to discuss it here. To connect to a database, you would need to know: 1. Host address - 95% is 'localhost' but sometimes it can be different.  Eg. for iPower, it should be 'username.ipowermysql.com'. 2. Database name 3. [...]

PHP/MySQL Tutorial Part 1

by Leo
Comments are off for this post.
I started using PHP with MySQL a few years ago.  I found that the world of PHP has no limit at all!  You can pretty much do anything you want. And because it is so large, people start telling me "I bought a book because I want to learn PHP.  But I just have no clue of where to start.".  The most important feature that PHP provides is its robustness when it comes to interacting with the database.  And yet, this is always the most desirable feature used getting to web programming. Hence I am writing this tutorial.  I am [...]