*Problem: cannot get data from (only)1 field of several in MySQL database* *Executive Summary: * There are 6 fields in the database. I can populate a form on a PHP page with date from 5 of the 6 fields. One field won't 'come across' to the...
Problem: cannot get data from (only)1 field of several in MySQL database
Executive Summary:
There are 6 fields in the database.
I can populate a form on a PHP page with date from 5 of the 6 fields.
One field won't 'come across' to the form
The questions:
1) why can't I retrieve data from column 'editd' - type timestamp(14)
2) what code will it take to retrieve that data?
3) when can I stop beating my head against the wall?
// the database
Code:
mysql> desc main;
+---------+-------------------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+---------+-------------------------------+------+-----+---------+----------------+
| id | smallint(4) unsigned zerofill | | PRI | NULL | auto_increment |
| fname | varchar(35) | YES | | NULL | |
| lname | varchar(35) | YES | | NULL | |
| title | varchar(35) | YES | | NULL | |
| editd | timestamp(14) | YES | | NULL | |
| editb | varchar(13) | YES | | NULL | |
+---------+-------------------------------+------+-----+---------+----------------+
6 rows in set (0.00 sec)
// a select statement from database
Code:
mysql> select id,fname,lname,title,editd,editb from main where id=941;
+------+------------+-------+--------------------+----------------+-----------------+
| id | fname | lname | title | editd | editb |
+------+------------+-------+--------------------+----------------+-----------------+
| 0941 | ZZ | Top | ***-kicking R & R | 20090128115610 | deus ex machina |
+------+------------+-------+--------------------+----------------+-----------------+
1 row in set (0.00 sec)
// use above to populate a form (see below)
// connect to server and open db
Code:
$connection = mysql_connect("localhost:3306","username","passwor d") or die("Darn! I couldn't connect to the server");
$db=mysql_select_db("roster",$connection) or die("Uh-oh! Connected to server but unable to open the database");
// run query (same as MySQL query above)
Code:
$query8=mysql_query("select fname,lname,title,editd,editb from main where id=$id", $connection);
// create an array from result set
Code:
$query9=mysql_fetch_assoc($query8);
$fname=$query9[fname];
$lname=$query9[lname];
$title=$query9[title];
$editd=$query9[editd];
$editb=$query9[editb];
// create form and populate fields
// ( all fields populate as expected except one):
// .... display data from columns 2-4 - get data from array
// .... display 5th field and data from array (display only, no edit)
Code:
echo "Last Edited Date:
".$editd."";
// sanity check - is the editd field passing a NULL value
Code:
if (is_null($editd))
{
$editd="Value passed is 'NULL'";
echo "Last Edited Date:
".$editd."";
}
// .... display 6th field and data from array - correctly
// ... end ...