1 / 18

The Basics of Using Databases

The Basics of Using Databases. What is a Database?. A place to store information Website can add or retrieve information. 3-Step Process. Create a database Make a form on a webpage Set up webpage to send information to the database. Creating a Database. Use program like MySQL

vevay
Télécharger la présentation

The Basics of Using Databases

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. The Basics of Using Databases

  2. What is a Database? • A place to store information • Website can add or retrieve information

  3. 3-Step Process • Create a database • Make a form on a webpage • Set up webpage to send information to the database

  4. Creating a Database • Use program like MySQL • Keep database (or multiple databases) on your server • Create tables in your database

  5. Database Tables Email Addresses Favorite Bands

  6. phpMyAdmin

  7. Making a Form Input tags <input type=“text” /> Types: “text” “radio” “checkboxes” “submit”

  8. Making a Form Put multiple “inputs” inside <form> </form> tags. Make the last one a “submit” button.

  9. <form> <dl> <dt>Text: </dt> <dl><input type="text" /></dl> <dt>Buttons: </dt> <dd><input type="radio" value="Option 1" />Option 1 <input type="radio" value="Option 2" />Option 2</dd> <dt>Checkboxes: </dt> <dd><input type="checkbox" value="Option 1" />Option 1 <input type="checkbox" value="Option 2" />Option 2</dd> <dt>Submit button: </dt> <dd><input type="submit" value="submit" /></dd> </dl> </form>

  10. Making the Form Useful Add attributes to the form tag: <form action=“sendToDatabase.php” method=“post”> ... </form> Add attributes to the input tags: <input type=“text” name=“email” /> We will need to make a PHPfile.

  11. What is PHP? • PHP is programming language • PHP files begin with <?php and end with ?> • PHP can be used to interface with MySQL easily

  12. What our PHP file needs to do • Connect to our database • Get that data from the form • “Escape” the data so it’s safe • Send the data to the database

  13. Beginning the PHP file <?php mysql_connect(“sql.mit.edu”, “jacob”, “psswd”); Server Address Username Password

  14. Getting the data from the form Recall the attributes we added to the form and the inputs: <form action=“sendToDatabase.php” method=“post”> <input type=“text” name=“email” /> $person = $_POST[`person`]; $email = $_POST[`email`];

  15. Sending data to the database mysql_query(“INSERT INTO `mydatabase`.`table1` (`ID`, `Name`, `Email`) VALUES (NULL, $name, $email)”); Queries can perform many different functions, including adding to the database, reading from the database, or ...

  16. xkcd.com

  17. Escaping the Input $email = mysql_real_escape_string($_POST[`email`]); Be careful!

  18. Questions?

More Related