I'm desinging a database as part of my archaeology masters in GIS I've been teaching myself apache server, php, mysql, html for the last month, its been a very steep learning curve and now i have got stuck: The database has an auto incremented ID number this is assigned on the 1st web page using the insert syntax this is then posted to the db the following pages simply update- but i dont know how to get it to select and store the id no. for that season? Also when i update the row each row gets written over therefore i want to set the primary key to the ID as well as a cookie - any ideas on how to do this? so far i have <?php setcookie(time()+3600); ?> This needs to be stored and remembered on each page so i assume i will need some kind of sql I have to tell the db that the newly created id no. is linked to the cookie so that all information from that user stays in the single row and does not over right any of the other data Thanks for you help Gary Nobles
to get the id of the last entry you added, you can use the php mysql_insert_id: $query = "INSERT INTO mytable VALUES('abc', 'def')"; mysql_query ($ query ) or die ( mysql_error ( ) ); $newest_id = mysql_insert_id ( ); PHP: you can either use a SESSION variable or a COOKIE variable to store the id of the visitor.
to set the cookie (and delete), you can use the setcookie variable: // this cookie will expire in an hour: setcookie ( 'cookie_name', 'cookie_value', time ( ) + 3600); // to delete a cookie: setcookie ( 'same_cookie_name_as_the_one_you_set_before', 'cookie_value', time ( ) - 3600); PHP: So to delete a cookie: you set the expiration time of the cookie to be on hour in the past. The visitors computer will then see that the cookie actually needed to be deleted an hour ago, and that's why it deletes them