***********************************************************************/ // new post function, returns codes based on outcome // 0 : all okay! // 1 : post text field empty // 2 : database error function doNewPost( $d ){ // first, let's check that we're actually posting some data if( empty( $d['text'] ) ) return 1; // now do the time // if we haven't gotten an expected timestamp, use the current time // else use the time provided // what a bastard of a regexp! if( !preg_match( '/^(19|20)\d\d-(0{0,1}[1-9]|1[012])-(0{0,1}[1-9]|[12][0-9]|3[0-1]) (0{0,1}[1-9]|1[0-9]|2[0123]):(0[1-9]|[12345][0-9]):(0[1-9]|[12345][0-9])$/', $d['time'] ) ) $d['time'] = date( 'Y-m-d H:i:s', time() ); // clean up our subject $d['title'] = htmlspecialchars( strip_tags( $d['title'] ) ); // enter the information into the database $sql = "INSERT INTO `blogentries` VALUES ( '', '$d[time]', '$d[title]', '$d[text]' );"; if( !mysql_query( $sql ) ) return 2; return 0; } ?>