Home / Archives /

PHP MySQL

PHP MySQL / 4 posts found

PHP Session Problem

by Leo
Comments are off for this post.
If you wrote websites in PHP, you would very likely be using PHP Session. Using PHP session allows you to preserve certain data across subsequent accesses.  Visitor of your site would be assigned a unique session id and would be propagated throughout his / her browsing session. However, a lot of inexperienced PHP programmers would have problems using it.  They might find it difficult to carry the session id to the other pages, or simply, no session id assigned. A quick checklist if you face this issue: Make sure <?php session_start(); ?> is at the very first line of the [...]

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. [...]