I have two questions:
#1. I want to run a query so that it gets results from a certain year (2006, 2005, 2004, etc). I'll declare the year in the code manually, but how do I get the year out of my TIMESTAMP (8) field. The format it YYYYMMDD, I just need to get the YYYY out and have the YYYY = 2006, or whatever I set it to.
#2. I have code to add 1 entry into the database. How do I go about adding two, or more entries? Do I need multiple queries?
For example, I have this html:
<input type="text" name="f_name1"> <input type="text" name="l_name1">
<input type="text" name="f_name2"> <input type="text" name="l_name2">
<input type="text" name="f_name3"> <input type="text" name="l_name3">
<input type="text" name="f_name4"> <input type="text" name="l_name4">
I want to enter all four entries into the database, if there is content in them. If for some reason a person only enters 3 of the 4 names, it only makes 3 entries into the database. Here's the code I normally use to enter info into the DB.
<?
// form not yet submitted
// display initial form
if (!$submit)
{
?>
// form content goes here
<?
}
else
{
// includes
include("connection-to-the-db-file.php");
// open database connection
$connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!");
// select database
mysql_select_db($db) or die ("Unable to select database!");
// generate and execute query
$query = "INSERT INTO bio(f_name, l_name) VALUES('$f_name1', '$l_name1')";
$result = mysql_query($query) or die ("Error in query: $query. " . mysql_error());
// print result
echo "This person has been added";
// close database connection
mysql_close($connection);
}
}
?>