is it possable that when a member registers on my web site it puts a date in a field in database cheers Doug
cheers i made a new field in database and called it date set it to time stamp whent back to web page made an entry then went back to database to look and nothing there except zeros do i have to put some more code some where cheers Doug i thought it did it auto
Here is a sample from the web, hope this helps. *********************************************************** <?php //This assumes you have created table named date & datetime in your database //Connect to DB echo "For Table Date Type Date"; $query_manual = "INSERT INTO date (type, date) VALUES ('DATE: Manual Date', '2008-7-26')"; $query_auto = "INSERT INTO date(type, date) VALUE ('DATE: Auto CURDATE()', CURDATE() )"; mysql_query($query_manual) or die(mysql_error()); mysql_query($query_auto) or die(mysql_error()); echo "For Table datetime Type Datetime"; $query_auto = "INSERT INTO datetime(type, datetime) VALUE ('DATE: Manual CURDATE()', CURDATE() )"; $query_auto = "INSERT INTO datetime(type, datetime) VALUE ('DATE: Auto NOW()', NOW() )"; mysql_query($query_manual) or die(mysql_error()); mysql_query($query_auto) or die(mysql_error()); ?> ************************************************************ HTH, GS Keep going Doug Appreciate your spirit Age is nothing but a fictitious notion of time
this is what i have done put this line on regform <input type="hidden" name="date" value="('DATE: Auto CURDATE()', CURDATE() )"> PHP: and this on add form $date=$_POST['date']; PHP: with this in the insert '$date' PHP: cheers Doug
Typically, I just have a field in my table called dt_stamp [data type : int(10) because the number of seconds since the Unix Epoch is still in the 10 digit range] Then in my PHP I create a variable: $sql_dt_stamp = time(); insert into table (dt_stamp) values ($sql_dt_stamp); By keeping it as a simple integer, you can do whatever you want with it down the road, as the PHP function date() accepts the Unix Epoch value, and since it's an integer, it's sortable. Just another way of doing it, maybe not the best, but it has always worked for me.
This is a terrible idea. The user could modify the date and submit something else... Why not just put the date stuff directly in the query string, so the user has no access to it?
this is the code i use for insert mysql_query("INSERT INTO `members` VALUES ('$id', '$region', '$name', '$username', '$password', '$email', '$contact' , '$parkname', '$county', '$parklocation', '$make', '$caravandetails', '$smoke', '$pets', '$kids', '$sex', '$pname', '$enq', '$date')"); PHP: so where would i put this code auto = "INSERT INTO date(type, date) VALUE ('DATE: Auto CURDATE()', CURDATE() )"; PHP: cheers Doug
ok have sorted it out it was so simple all i had to do was add this line $date = date("d-m-Y"); PHP: does just what i wanted it to cheers for all the help Doug
Why writting the date with php ? Just use SQL's NOW() function. Best thing to do is have the date field created with something like that: date date NOT NULL DEFAULT NOW() Code (markup): and you'll never even have to insert values in this field. Just insert the other values and don't bother even listing the 'date' column in you INSERT query, it will automatically get the current date.
use NOW() on datetime data type table column use CURDATE() on date data type table column If you use date data type then your query will look like this. "INSERT INTO tablename(name,today) VALUES('Finau',CURDATE())"; if you use datetime data type then your query will look like this. "INSERT INTO tablename(name,login_time) VALUES('Finau',NOW())";