Doublea Posted April 11, 2011 Share Posted April 11, 2011 Hi guys, I think I may be losing my marbles over this form I've put together. I'm trying to get my code to post the following to a database but my MySQL and PHP isn't that good, so wondering if any one could possibly suggest what I could do? Here is my code: <?php // we check if everything is filled in if(empty($_POST['fname']) || empty($_POST['lname']) || empty($_POST['email'])) { die(msg(0,"All the fields are required")); } // is the sex selected? if(!(int)$_POST['sex-select']) { die(msg(0,"You have to select your sex")); } // is the birthday selected? if(!(int)$_POST['day'] || !(int)$_POST['month'] || !(int)$_POST['year']) { die(msg(0,"You have to fill in your birthday")); } // is the email valid? if(!(preg_match("/^[\.A-z0-9_\-\+]+[@][A-z0-9_\-]+([.][A-z0-9_\-]+)+[A-z]{1,4}$/", $_POST['email']))) die(msg(0,"You haven't provided a valid email")); // I think here is where I need to put something to get the data into a table! echo msg(1,"registered.html"); function msg($status,$txt) { return '{"status":'.$status.',"txt":"'.$txt.'"}'; } ?> How do I get the $_POST['day'] and $_POST['month'], $_POST['year'] etc into a table? It should be so easy but my head is hurting from trying lots of things and tutorials online. Any thoughts my PHP Freaks? Quote Link to comment https://forums.phpfreaks.com/topic/233393-post-data/ Share on other sites More sharing options...
spiderwell Posted April 11, 2011 Share Posted April 11, 2011 mysql accepts dates as yyyy-mm-dd try $date ="$_POST['year']-$_POST['month']-$_POST['day']" this assumes your values are numbers not words, e.g. month is 12 not december Quote Link to comment https://forums.phpfreaks.com/topic/233393-post-data/#findComment-1200305 Share on other sites More sharing options...
Pikachu2000 Posted April 11, 2011 Share Posted April 11, 2011 Not to be harsh, but that code should be completely redone. I doubt that any of it is actually doing what you think it is doing. What happens when you submit the form and that code is executed? Quote Link to comment https://forums.phpfreaks.com/topic/233393-post-data/#findComment-1200308 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.