Does that make sense?
no. html is markup. i.e. formatting. It doesn't do anything. A database is something that holds data (obviously

). Exaples are MySQL, MSSQL, Oracle...
Go get phpMyAdmin if you don't already have it. It makes MySQL easy.
If you have hosting somewhere, then they probably make you create a database somewhere else, then edit it in phpMyAdmin. Here's a good example database..thing.
- First, create a database (somehow). Your host should have a "Create Database" link somewhere. Name it
testing.
- Second, go into phpMyAdmin and click the dropdown on the left and choose
testing.
- Third, where it says "Create new table on database testing:" enter the name
testtable and 3 rows.
- Fourth:
-- name the fields
id,
number, and
data. Choose types smallint, int, and varchar. Input lengths of 3, 10, and 40.
This means that id will be limited to three characters long, number to 10, and data to 40. varchar is a string. For id, choose unsigned from the attributes dropdown, select auto_increment from the extra dropdown, and click the radio under the icon that has a key on it. unsigned means it's a positive integer. auto_increment means it will inc by one for each row you add. the key icon means it's a primary index.
-- click create.
-- Look at the code it shows you (the CREATE TABLE code). Compare it with the rows in the table.
- NEXT, we insert data... Instead of using phpMyAdmin's insert tab, do this in the little query box below the table. (By default it should say "SELECT * FROM testtable WHERE 1.")
-- type in:
INSERT INTO testtable VALUES('','12345','test string');
and click Go.
-- Now type in:
SELECT * FROM testtable;
-- Look at the data there and compare it with the INSERT string.
- Alrighty! So you should have a basic idea of what a database is. yay.
To insert data from a php file, you have to first connect, then select the database, then query it.
Code: Select all
<?php
mysql_connect('localhost','username','password'); // fill in the variables appropriately
mysql_select_db('testing');
mysql_query("INSERT INTO testtable VALUES('','54321','another string')"); // the auto_increment field is empty, but there!
$result = mysql_query("SELECT * FROM testtable ORDER BY number");
while ($row = mysql_fetch_assoc($result)) {
print("$row['id'] = " . $row['id'] . "\n" .
"$row['number'] = " . $row['number'] . "\n" .
"$row['data'] = " . $row['data'] . "\n\n");
}
mysql_close(); // always have this.
?>
so to input data from an html form...
Code: Select all
<?php
if (isset($_GET['txt'])) {
$txt = mysql_escape_string($_GET['txt']); // ALWAYS have this for user entered data. You should normally do other checks as well.
$time = time();
//assuming we're already connected to the database, and that we'll close later...
mysql_query("INSERT INTO testtable VALUES('','$time','$txt')");
}
else {
print("<form><input type='text' name='txt' /><input type='submit' value='Add Data' /></form>");
}
?>
wow. databases 101. *shrugs* hopefully you find it helpful.