Category: Web Development

Simple PHP MySQL Database Functions

A simple bit of code to make PHP database connections a little easier to use.<?phpfunction db_connect(){ $db = mysql_connect(DB_HOST,DB_USER,DB_PASS) or die(“Cannot connect”); $dbcnx = mysql_select_db(DB_NAME) or die (“Cannot select db”); return $db;}function query($sql,$db){ $res = mysql_query($sql,$db) or die(“Error in sql $sql: “.mysql_error()); return $res;}function qa($sql,$db){ $res = query($sql,$db); $data = array(); while($row = mysql_fetch_assoc($res)){ if($res[‘id’])$data[$res[‘id’]] […]

Remember Form Data on Back Button

Sometimes it’s handy to have the browser cache an entire page including anything that is entered into a form. What if a user has filled out an entire form but accidently clicks refresh or another link, and when they click back the form is empty. Anoying! This also works if you submit to an error […]