PHP - Small Date Of Birth Menu Generator I Wrote -> How To Make Code Copy-able?
Since I didn't want to type it out myself I wrote a small Date of Birth drop down menu generator.
Now I'm wondering how I can make the code copy-able in a text area? The script should be inserting all the code ready and finished into a textarea so you can copy and go. How is it done? Here's the script: <?php echo "<center>"; ?> <form action='' method='POST'> <input type='submit' name='submit' /> </form> <?php $submit = $_POST['submit']; if ($submit) { echo "<form action='' method='POST'>"; echo "<select name='month'>"; for ($m = 01; $m <= 12; $m++) { echo " <option value='" . $m . "'>" . $m . "</option> "; } echo "</select>"; echo "<select name='day'>"; for ($d = 01; $d <= 31; $d++) { echo " <option value='" . $d . "'>" . $d . "</option> "; } echo "</select>"; echo "<select name='year'>"; for ($y = 1900; $y <= 2010; $y++) { echo " <option value='" . $y . "'>" . $y . "</option> "; } echo "</select>"; echo "</form>"; echo "</center>"; } ?> Similar TutorialsStarted learning PHP a few weeks ago, I want to ask if anyone can give me some feedback (warnings, pointers, ...) about some code I wrote, with the objective to learn more about functions as well as MySQL. I created three functions, one to create a new table (in an existing DB), one to add a new Record and one to delete an existing record. Next I want to try to use an array as parameters for these functions. Code: [Select] <?php require 'DB.php'; // Connection string mysql_connect("localhost", "root", "") or die(mysql_error()); /* echo "Connected to MySQL<br />"; */ mysql_select_db("test") or die(mysql_error()); /* echo "Connected to Database"; */ // Create a MySQL table in the selected database function newTable($tableName) { mysql_query("CREATE TABLE IF NOT EXISTS $tableName ( id INT NOT NULL AUTO_INCREMENT, PRIMARY KEY(id), name VARCHAR(30), age INT)") or die(mysql_error()); } // Insert Two values in the corresponding rows in table $tableName function newRecordTwoVal ($tableName, $recordName1, $recordName2, $recordVal1, $recordVal2) { $myQuery=mysql_query("SELECT * FROM $tableName WHERE $recordName1=$recordVal1 AND $recordName2='$recordVal2';"); $doesItExist= mysql_fetch_array($myQuery); if ($doesItExist) { print ('Person already exists'); } else { mysql_query("INSERT INTO $tableName ($recordName1, $recordName2) VALUES('$recordVal1', '$recordVal2'); ") or die(mysql_error()); echo "Data Inserted!"; } } function delRecord ($tableName, $recordName1, $recordName2, $recordVal1, $recordVal2) { $myQuery=mysql_query("DELETE FROM $tableName WHERE $recordName1=$recordVal1 AND $recordName2='$recordVal2';"); } newTable('Moderators'); newRecordTwoVal ('Moderators', 'age', 'name', '40', 'Jack'); delRecord('Moderators', 'age', 'name', '40', 'Jack'); ?> Hi guys, My apologies if this is in the wrong forum but I am not really sure how to go about this. I have not written any code for this but I have four fields in one table one called age and 3 others dobmonth / dobday /dobyear - My question being how would I write some code that automatically fills in the age field based on the date of birth fields? If anyone could point me in the right direction that would be awesome, Appreciated. Is there a way to add a date of birth into a mysql but display it as the age?... e.g Mysql = 04/06/89 Display = 21 i have date of birth stored as DATE type in mysql. i tried this so it would show the age but it comes up blank. Code: [Select] $getprof = mysql_query("SELECT * FROM Profile WHERE username='$search'")or die(mysql_error()); while($rowprof = mysql_fetch_assoc($getprof)) { $username1 = $rowprof['username']; $location = $rowprof['location']; $gender = $rowprof['gender']; $dateofbirth = $rowprof['dateofbirth']; $information = $rowprof['information']; } function GetAge($dateofbirth) { // Explode the date into meaningful variables list($BirthYear,$BirthMonth,$BirthDay) = explode("-", $dateofbirth); // Find the differences $YearDiff = date("Y") - $BirthYear; $MonthDiff = date("m") - $BirthMonth; $DayDiff = date("d") - $BirthDay; // If the birthday has not occured this year if ($DayDiff < 0 || $MonthDiff < 0) $YearDiff--; return $YearDiff; } echo $YearDiff; Hi all, I'm having a bit of trouble a script running on a site where it converts a date of birth in a database shown like this '30/04/1993' to an actual age, for instance 18 in this case. Only the script I'm using below shows this age as 17, not 18 as it should be. Code: [Select] <?php $birthday = $row_getdets['dob']; function birthday ($birthday){ list($day,$month,$year) = explode("/",$birthday); $day_diff = date("d") - $day; $month_diff = date("m") - $month; $year_diff = date("Y") - $year; if ($day_diff < 0 || $month_diff < 0) $year_diff--; return $year_diff; } ?> So i've tried to remedy this myself with the following: Code: [Select] <?php $birthday = $row_getdets['dob']; function birthday ($birthday){ list($year,$month,$day) = explode("/",$birthday); $year_diff = date("Y") - $year; $month_diff = date("m") - $month; $day_diff = date("d") - $day; if ($month_diff < 0) $year_diff--; else if (($month_diff==0) && ($day_diff < 0)) $year_diff--; return $year_diff; } ?> ..but I'm having a syntax error (unexpected T_LINE), most probably down to my novice ability, I bet I've missed something simple. I'm still learning guys and I'd really appreciate any help at all. I need to add date of birth field to registration form and then save it to databse. I cannot figure out what might be best way of storing the date in the table. I could convert it to unix epoch time, or I could do YYYYMMDD.
Thoughts? What would be the easiest method of saving the DOB?
I am not asking on how to do it, just the format. Thanks
Hi there, I'm new to PHP so sorry if this is a really basic question. How do i post date of birth collected from a form, into a database? I have the fields in the form set up as 'day' 'month' 'year' all of which are drop-down boxes. I tried doing it one way which i saw on a different website, but it didn't work. Here is what i tried: Code: [Select] '$_POST[day] . - . $_POST[month]' . - . $_POST[year]', More info: In the database table this information is going to, the "date of birth" field is set to "DATE" type. Don't know if that makes any difference hello fellas, need some help please if possible. i have created a date of birth section in my form where the user selects his/her date of birth from the dropdown menu. they would first select the day then month then year of their birthday. how would i setup the database to get this to work? i currently have: Code: [Select] day VARCHAR( 2 ) NOT NULL , month VARCHAR( 4 ) NOT NULL , year VARCHAR( 4 ) NOT NULL , is this correct? many thanks Can you please help how to validate the date of birth in code igniter including leap years
$username = $_POST['username']; $password = $_POST['password']; $month = $_POST['month']; $day = $_POST['day']; $year = $_POST['year']; $query = mysql_query("INSERT INTO users VALUES ('','$username','$password','$month','$day','$year') mysql_query($query); The code above is a sample of what I have but what I want is to store an entire birthdate in ONE SQL cell. More like this... $username = $_POST['username']; $password = $_POST['password']; $month = $_POST['month']; $day = $_POST['day']; $year = $_POST['year']; $query = mysql_query("INSERT INTO users VALUES ('','$username','$password','$birthdate') mysql_query($query); How is this possible? Can I do this and actually use it efficiently in the future? I have PHP code that generates a long list of Birth Years in a Drop-down list, and I want to make the control "sticky". I know how to make something like this sticky - thanks to help from you guys... Code: [Select] <!-- Gender --> <label for="gender">Gender:</label> <select id="gender" name="gender"> <option value="">--</option> <option value="F"<?php echo (isset($gender) && $gender == "F") ? 'selected="selected"' : ''; ?>>Female</option> <option value="M"<?php echo (isset($gender) && $gender == "M") ? 'selected="selected"' : ''; ?>>Male</option> </select> But my Birth Year code is a little more complex and I'm racking me brain how to do it... Code: [Select] <!-- Birth Year --> <label for="birthYear">Year Born:</label> <select id="birthYear" name="birthYear"> <option value="">--</option> <?php // Display dates for Users between 18 and 100. for($i = $newestYear; $i >= $oldestYear; $i--){ echo '<option value="' . $i . '">' . $i . '</option>'; } ?> </select> How do I make this second set of code "sticky"?? Thanks, Debbie I am having some issues with getting dates for the days of the week based on one date givin Example: User enters date for sunday. (Ending pay period) and I wish to get the dates for that week. Mon - 1-2-2012 Tue - 1-3-2012 Wed - 1-4-2012 Thu - 1-5-2012 Fri - 1-6-2012 Sat - 1-7-2012 Sun - 1-8-2012 User would enter 1/8/2012 and the script would get the rest of the dates to enter into the timecard. I have tried both ways below and cant get it to work no mater if i change the user input date i still get the same output. Function getdatepast($dtp,$cnt) { $undatecon = mktime($dtp); $undatecon2 = strtotime("-".$cnt." day", $undatecon); $ddt1 = date('m-d-Y',($undatecon2)); return $ddt1; } Function getdatepast($dtp,$cnt) { $undatecon = mktime($dtp); $undatecon2 = $undatecon - (86400 * ($cnt)); $ddt1 = date('m-d-Y',($undatecon2)); return $ddt1; } I used to code a long time ago - PHP5. It is slowly coming back to me but not fast enough... I need to copy data from a mysql data base and put it back in unchanged with another date reference. This is a calorie recorder that tracks daily calories - food type, calories, protein, carbs, etc. I simply want to take each entry in that day, then copy it exactly except changing the date recerence. If I could say "copy all entires where date = (date) into DB with new date (date), that would do it. The only thing I can think to do is pull each item out and place it back into the DB with a while statement. There has to be an easier way... If that is my only option, I need to figure out how to create a while statement to handle an array to do the job. Any thoughts? Thanks for the help!! David Hi there, on my yardmaps website, if a user uploads an image taken with an iphone, and the exif data sets orientation to 1, the image is automatically rotated when put through the imagecopyresampled function. If I take the same image, and strip out the exif data with photoshop (save as for web, no meta data), the image uploads correctly. Is there any way to force imagecopyresampled to not rotate the image? Thanks B Hi all, I've been working with PHP for the past month to develop a simple web-site. It has two pages that are served dynamically - the events page and the members page. These are public pages. It has 3 other static pages. I've created the database tables in MYSql. The events page has one table. And the teachers page has a few more - particularly - one primary table for member basics, another for member address. These are one to one with the primary driver being the member basic table since it will also include an active/inactive flag. The 2 files that get used are member credentials, and member specialties. These have one to many relationship with basics table. So far I've been using PHPadmin to create dummy data. But my next step is to create an admin page for the events - where the admin can maintain any event. Then I need to create an admin page for the users. (Further down the line each user will be able to maintain their own events and information.) I was actually hoping to find a code generator to help with these. I know it would be a great learning experience to do them on my own. But I would also like to move a little faster than glacial speed. I'm an RPG programmer by day. So I have programming experience - just new to the web. I've looked at MySQl Table Editor from phpguru. But it used Pear - which I'm not using. And it's not clear to me whether/how it will handle the one to many relationships. I also looked at PhpMyEdit - but it looks like overkill and some of the documentation I've seen recommends that the first column in every table be unique(auto incremented) and I haven't done that with the children tables that have a one to many relationship. And I'm not quite sure why I would do that. Can anyone recommend a tool??? And/or a really good tutorial that includes multiple file being updated at the same time? I'd rather not reinvent the wheel. I apologize for the long first post. I've tried to google - but I actually kind of overwhelmed by the amount of material I find on PHP. Thanks. Vic Hi all. I have a singleton database class that just basically extends PDO. I then created a file called configure.php that will be included on every single page in my small application. In this file, I get the database instance and also instantiate a Site class that returns information about the site, pages, etc. Well, for some reason my Site class is not reading the $database variable that is defined in the configure.php file. I am getting the following error: "Notice: Undefined variable: database in C:\xampp\htdocs\individualbasic\libraries\Site.php on line 30 Fatal error: Call to a member function prepare() on a non-object in C:\xampp\htdocs\individualbasic\libraries\Site.php on line 30". Below are my files. Thanks in advance. Database.php Code: [Select] <?php class Database extends PDO { public static $_instance; public function __construct() { try { parent::__construct(DB_TYPE . ':host=' . DB_HOST . ';dbname=' . DB_NAME, DB_USER, DB_PASS); } catch (PDOException $e) { $this->error = $e->getMessage(); } } public static function getInstance() { if (!self::$_instance) { self::$_instance = new Database(); } return self::$_instance; } public function __destruct() { // I want to close the connection here. } } Site.php Code: [Select] <?php class Site { /** * Checks the validity of the site token with the token in the MinorCorp database. */ public function __construct() { /*try { $query = $database->prepare("SELECT individual_site_url, individual_site_token FROM individual_site WHERE individual_site_url = ? AND individual_site_token = ? AND individual_site_active = 1"); $result = $query->execute(array(SITE_URL, SITE_TOKEN)); if (count($result) == 1) { return TRUE; } die('Your website is not valid.'); } catch (Exception $e) { echo $e; }*/ } /** * Retrieves vital information about each page. */ public function page($page) { try { $query = $database->prepare("SELECT page_title, page_keywords, page_description, page_content, page_image FROM page WHERE page_name = ?"); $query->execute(array($page)); return $query->fetch(); } catch (Exception $e) { echo $e; } } /** * Retrieves bottom advertisements from the MinorCorp database. */ public function bannerAd() { try { } catch (Exception $e) { echo $e; } } /** * Retrieves vital information about each page. */ public function sidebarAd() { try { } catch (Exception $e) { echo $e; } } } configure.php (This is the file that is included on every page) Code: [Select] <?php include_once('configuration/configuration.php'); require_once('libraries/Database.php'); $database = Database::getInstance(); require_once('libraries/Site.php'); $site = new Site(); $pageInfo = $site->page($page); $bottomAd = $site->bannerAd(); $sidebarAd = $site->sidebarAd(); Hi All I want to use wiki style bold (''') and italic ('') code form my form. So, it would be easy to use str_replace() for the opening tag but if you are using '''hello''' to bold the word hello, how can you differentiate the tags? I guess you would need some code to replace this alternatively but I haven't been able to find anything. I think Wikis are built from php so has anyone got any ideas? Many thanks Ian Alright, I have a Datetime field in my database which I'm trying to store information in. Here is my code to get my Datetime, however it's returning to me the wrong date. It's returning: 1969-12-31 19:00:00 $mysqldate = date( 'Y-m-d H:i:s', $phpdate ); $phpdate = strtotime( $mysqldate ); echo $mysqldate; Is there something wrong with it? Hi guys, I am wirting a script to upload an image file, but I get the error: copy() [function.copy]: Filename cannot be empty in Obviouly it has something to do with the copy() function - (copy($HTTP_POST_FILES['product_img']['tmp_name'], $path)) I think it is not copying from my temp folder or something. Can anyone help me out? Code is: Code: [Select] //IMAGE FILE $file_name = $_FILES['product_img']['name']; echo '<p>File Name:' . $file_name . '</p>'; //IMAGE UPLOAD // random 4 digit to add to file name $random_digit=rand(0000,9999); //combine random digit to file name to create new file name //use dot (.) to combile these two variables $new_image_name = $random_digit.$file_name; echo $new_image_name; //SET DESINATION FOLDER $path= "uploads/".$new_image_name; echo '<p>Path:' . $path . '</p>'; if($product_img !=none) { if(copy($HTTP_POST_FILES['product_img']['tmp_name'], $path)) { echo "Successful<BR/>"; echo "File Name :".$new_file_name."<BR/>"; echo "File Size :".$HTTP_POST_FILES['product_img']['size']."<BR/>"; echo "File Type :".$HTTP_POST_FILES['product_img']['type']."<BR/>"; } else { echo "Image upload Error<BR/>"; } } Any help would be greatly appreciated! Thanks Ok I am designing a php upload that will take a image file from a form and change the name of the file to the productnumber also recieved from the form. I had it working the otherday now it says Warning: copy() [function.copy]: open_basedir restriction in effect File() is not within the allowed path(s): (/home:/tmp:/usr) addpro.php on line 51. my files are attached.... note that $pnum is the product number gotten from my form and image is the image being uploaded gotten from the form also. The thing is it worked the other day but now it don't is it a change to the server ( I dont run the server) or did I mess up my code since then? I really need a code that will do this two time over once for a small image being put into a folder called small and once for a folder called large both images being uploaded and being changed to $pnum.ext so they will both be displayed when being called out by the product number. but I can work on that after I get this one working. line 51 is $copied = copy($_FILES['image']['tmp_name'], $newname); |