PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
mikes1471
Forum Commoner
Posts: 88 Joined: Sat Jan 24, 2009 3:29 pm
Post
by mikes1471 » Mon Feb 02, 2009 4:36 pm
Hi Folks
I'm looking to introduce this string into my registration page
Code: Select all
$birthdate = $birthday . "/" . $birthmonth . "/" . $birthyear;
$birthdate = protect($_POST['birthdate']);
but when i submit the registration form the date doesnt reach the database
I'm pretty sure the string is fine, so i think the question is where in my code should it go?
Skoalbasher
Forum Contributor
Posts: 147 Joined: Thu Feb 07, 2008 8:09 pm
Post
by Skoalbasher » Mon Feb 02, 2009 4:38 pm
If it's MYSQL and you're entering into a date field, I know that's not the correct way to do it.
YYYY-MM-DD i think if I remember right. Maybe that's what.
mikes1471
Forum Commoner
Posts: 88 Joined: Sat Jan 24, 2009 3:29 pm
Post
by mikes1471 » Mon Feb 02, 2009 4:44 pm
It is mySQL but I've not specified it as a date field
kwdamp
Forum Newbie
Posts: 6 Joined: Mon Feb 02, 2009 4:41 pm
Post
by kwdamp » Mon Feb 02, 2009 4:50 pm
why don't you test the mysql insert by trying to insert
$today = date('Y-m-d');
This should yield 2009-02-02
Skoalbasher
Forum Contributor
Posts: 147 Joined: Thu Feb 07, 2008 8:09 pm
Post
by Skoalbasher » Mon Feb 02, 2009 4:57 pm
Also this is in the registration.php or in the handle.php you have?
mickeyunderscore
Forum Contributor
Posts: 129 Joined: Sat Jan 31, 2009 9:00 am
Location: UK
Post
by mickeyunderscore » Mon Feb 02, 2009 4:59 pm
Code: Select all
$birthdate = $birthday . "/" . $birthmonth . "/" . $birthyear;
$birthdate = protect($_POST['birthdate']);
I'm not sure I follow the logic, this code assigns a string ($birthday/$birthmonth/$birthyear), to the variable $birthdate.
It then assigns the value of $_POST['birthdate'] to the variable $birthdate, overriding the previous line?
What else is your form posting to this script?
mikes1471
Forum Commoner
Posts: 88 Joined: Sat Jan 24, 2009 3:29 pm
Post
by mikes1471 » Mon Feb 02, 2009 5:01 pm
Yes this is in registration.php
mikes1471
Forum Commoner
Posts: 88 Joined: Sat Jan 24, 2009 3:29 pm
Post
by mikes1471 » Mon Feb 02, 2009 5:02 pm
Code: Select all
}else {
$firstname = protect($_POST['firstname']);
$lastname = protect($_POST['lastname']);
$email = protect($_POST['email']);
$emailconf = protect($_POST['emailconf']);
$gender = protect($_POST['gender']);
$sexuality = protect($_POST['sexuality']);
$birthdate = $birthday . "/" . $birthmonth . "/" . $birthyear;
$birthdate = protect($_POST['birthdate']);
$street = protect($_POST['street']);
$city = protect($_POST['city']);
$postcode = protect($_POST['postcode']);
$country = protect($_POST['country']);
$username = protect($_POST['username']);
$password = protect($_POST['password']);
$confirm = protect($_POST['passconf']);
mickeyunderscore wrote: Code: Select all
$birthdate = $birthday . "/" . $birthmonth . "/" . $birthyear;
$birthdate = protect($_POST['birthdate']);
I'm not sure I follow the logic, this code assigns a string ($birthday/$birthmonth/$birthyear), to the variable $birthdate.
It then assigns the value of $_POST['birthdate'] to the variable $birthdate, overriding the previous line?
What else is your form posting to this script?
mikes1471
Forum Commoner
Posts: 88 Joined: Sat Jan 24, 2009 3:29 pm
Post
by mikes1471 » Mon Feb 02, 2009 5:03 pm
I thought line 9 would post the result of line 8
mickeyunderscore
Forum Contributor
Posts: 129 Joined: Sat Jan 31, 2009 9:00 am
Location: UK
Post
by mickeyunderscore » Mon Feb 02, 2009 5:07 pm
From what I can see $birthday, $birthmonth and $birthyear contain nothing, so at line 8 you assign '//' to the $birthdate variable, then override it with $_POST['birthdate']. Do you have a form input named 'birthdate'?
mikes1471
Forum Commoner
Posts: 88 Joined: Sat Jan 24, 2009 3:29 pm
Post
by mikes1471 » Mon Feb 02, 2009 5:16 pm
I guess not, just birthday, birthmonth and birthyear:
Code: Select all
<tr><td>Date of Birth</td><td><select size="1" name="birthday">
<option>Day</option>
<option <?php echo ($birthday == '1') ? 'selected' : ''; ?>>1</option>
<option <?php echo ($birthday == '2') ? 'selected' : ''; ?>>2</option>
<option <?php echo ($birthday == '3') ? 'selected' : ''; ?>>3</option>
<option <?php echo ($birthday == '4') ? 'selected' : ''; ?>>4</option>
<option <?php echo ($birthday == '5') ? 'selected' : ''; ?>>5</option>
<option <?php echo ($birthday == '6') ? 'selected' : ''; ?>>6</option>
<option <?php echo ($birthday == '7') ? 'selected' : ''; ?>>7</option>
<option <?php echo ($birthday == '8') ? 'selected' : ''; ?>>8</option>
<option <?php echo ($birthday == '9') ? 'selected' : ''; ?>>9</option>
<option <?php echo ($birthday == '10') ? 'selected' : ''; ?>>10</option>
<option <?php echo ($birthday == '11') ? 'selected' : ''; ?>>11</option>
<option <?php echo ($birthday == '12') ? 'selected' : ''; ?>>12</option>
<option <?php echo ($birthday == '13') ? 'selected' : ''; ?>>13</option>
<option <?php echo ($birthday == '14') ? 'selected' : ''; ?>>14</option>
<option <?php echo ($birthday == '15') ? 'selected' : ''; ?>>15</option>
<option <?php echo ($birthday == '16') ? 'selected' : ''; ?>>16</option>
<option <?php echo ($birthday == '17') ? 'selected' : ''; ?>>17</option>
<option <?php echo ($birthday == '18') ? 'selected' : ''; ?>>18</option>
<option <?php echo ($birthday == '19') ? 'selected' : ''; ?>>19</option>
<option <?php echo ($birthday == '20') ? 'selected' : ''; ?>>20</option>
<option <?php echo ($birthday == '21') ? 'selected' : ''; ?>>21</option>
<option <?php echo ($birthday == '22') ? 'selected' : ''; ?>>22</option>
<option <?php echo ($birthday == '23') ? 'selected' : ''; ?>>23</option>
<option <?php echo ($birthday == '24') ? 'selected' : ''; ?>>24</option>
<option <?php echo ($birthday == '25') ? 'selected' : ''; ?>>25</option>
<option <?php echo ($birthday == '26') ? 'selected' : ''; ?>>26</option>
<option <?php echo ($birthday == '27') ? 'selected' : ''; ?>>27</option>
<option <?php echo ($birthday == '28') ? 'selected' : ''; ?>>28</option>
<option <?php echo ($birthday == '29') ? 'selected' : ''; ?>>29</option>
<option <?php echo ($birthday == '30') ? 'selected' : ''; ?>>30</option>
<option <?php echo ($birthday == '31') ? 'selected' : ''; ?>>31</option>
</select>
<select size="1" name="birthmonth">
<option>Month</option>
<option <?php echo ($birthmonth == 'January') ? 'selected' : ''; ?>>January</option>
<option <?php echo ($birthmonth == 'February') ? 'selected' : ''; ?>>February</option>
<option <?php echo ($birthmonth == 'March') ? 'selected' : ''; ?>>March</option>
<option <?php echo ($birthmonth == 'April') ? 'selected' : ''; ?>>April</option>
<option <?php echo ($birthmonth == 'May') ? 'selected' : ''; ?>>May</option>
<option <?php echo ($birthmonth == 'June') ? 'selected' : ''; ?>>June</option>
<option <?php echo ($birthmonth == 'July') ? 'selected' : ''; ?>>July</option>
<option <?php echo ($birthmonth == 'August') ? 'selected' : ''; ?>>August</option>
<option <?php echo ($birthmonth == 'September') ? 'selected' : ''; ?>>September</option>
<option <?php echo ($birthmonth == 'October') ? 'selected' : ''; ?>>October</option>
<option <?php echo ($birthmonth == 'November') ? 'selected' : ''; ?>>November</option>
<option <?php echo ($birthmonth == 'December') ? 'selected' : ''; ?>>December</option>
</select>
<select size="1" name="birthyear">
<option>Year</option>
<option <?php echo ($birthyear == '1991') ? 'selected' : ''; ?>>1991</option>
<option <?php echo ($birthyear == '1990') ? 'selected' : ''; ?>>1990</option>
<option <?php echo ($birthyear == '1989') ? 'selected' : ''; ?>>1989</option>
<option <?php echo ($birthyear == '1988') ? 'selected' : ''; ?>>1988</option>
<option <?php echo ($birthyear == '1987') ? 'selected' : ''; ?>>1987</option>
<option <?php echo ($birthyear == '1986') ? 'selected' : ''; ?>>1986</option>
<option <?php echo ($birthyear == '1985') ? 'selected' : ''; ?>>1985</option>
<option <?php echo ($birthyear == '1984') ? 'selected' : ''; ?>>1984</option>
<option <?php echo ($birthyear == '1983') ? 'selected' : ''; ?>>1983</option>
<option <?php echo ($birthyear == '1982') ? 'selected' : ''; ?>>1982</option>
<option <?php echo ($birthyear == '1981') ? 'selected' : ''; ?>>1981</option>
<option <?php echo ($birthyear == '1980') ? 'selected' : ''; ?>>1980</option>
<option <?php echo ($birthyear == '1979') ? 'selected' : ''; ?>>1979</option>
<option <?php echo ($birthyear == '1978') ? 'selected' : ''; ?>>1978</option>
<option <?php echo ($birthyear == '1977') ? 'selected' : ''; ?>>1977</option>
<option <?php echo ($birthyear == '1976') ? 'selected' : ''; ?>>1976</option>
<option <?php echo ($birthyear == '1975') ? 'selected' : ''; ?>>1975</option>
<option <?php echo ($birthyear == '1974') ? 'selected' : ''; ?>>1974</option>
<option <?php echo ($birthyear == '1973') ? 'selected' : ''; ?>>1973</option>
<option <?php echo ($birthyear == '1972') ? 'selected' : ''; ?>>1972</option>
<option <?php echo ($birthyear == '1971') ? 'selected' : ''; ?>>1971</option>
<option <?php echo ($birthyear == '1970') ? 'selected' : ''; ?>>1970</option>
<option <?php echo ($birthyear == '1969') ? 'selected' : ''; ?>>1969</option>
<option <?php echo ($birthyear == '1968') ? 'selected' : ''; ?>>1968</option>
<option <?php echo ($birthyear == '1967') ? 'selected' : ''; ?>>1967</option>
<option <?php echo ($birthyear == '1966') ? 'selected' : ''; ?>>1966</option>
<option <?php echo ($birthyear == '1965') ? 'selected' : ''; ?>>1965</option>
<option <?php echo ($birthyear == '1964') ? 'selected' : ''; ?>>1964</option>
<option <?php echo ($birthyear == '1963') ? 'selected' : ''; ?>>1963</option>
<option <?php echo ($birthyear == '1962') ? 'selected' : ''; ?>>1962</option>
<option <?php echo ($birthyear == '1961') ? 'selected' : ''; ?>>1961</option>
<option <?php echo ($birthyear == '1960') ? 'selected' : ''; ?>>1960</option>
<option <?php echo ($birthyear == '1959') ? 'selected' : ''; ?>>1959</option>
<option <?php echo ($birthyear == '1958') ? 'selected' : ''; ?>>1958</option>
<option <?php echo ($birthyear == '1957') ? 'selected' : ''; ?>>1957</option>
<option <?php echo ($birthyear == '1956') ? 'selected' : ''; ?>>1956</option>
<option <?php echo ($birthyear == '1955') ? 'selected' : ''; ?>>1955</option>
<option <?php echo ($birthyear == '1954') ? 'selected' : ''; ?>>1954</option>
<option <?php echo ($birthyear == '1953') ? 'selected' : ''; ?>>1953</option>
<option <?php echo ($birthyear == '1952') ? 'selected' : ''; ?>>1952</option>
<option <?php echo ($birthyear == '1951') ? 'selected' : ''; ?>>1951</option>
<option <?php echo ($birthyear == '1950') ? 'selected' : ''; ?>>1950</option>
<option <?php echo ($birthyear == '1949') ? 'selected' : ''; ?>>1949</option>
<option <?php echo ($birthyear == '1948') ? 'selected' : ''; ?>>1948</option>
<option <?php echo ($birthyear == '1947') ? 'selected' : ''; ?>>1947</option>
<option <?php echo ($birthyear == '1946') ? 'selected' : ''; ?>>1946</option>
<option <?php echo ($birthyear == '1945') ? 'selected' : ''; ?>>1945</option>
<option <?php echo ($birthyear == '1944') ? 'selected' : ''; ?>>1944</option>
<option <?php echo ($birthyear == '1943') ? 'selected' : ''; ?>>1943</option>
<option <?php echo ($birthyear == '1942') ? 'selected' : ''; ?>>1942</option>
<option <?php echo ($birthyear == '1941') ? 'selected' : ''; ?>>1941</option>
<option <?php echo ($birthyear == '1940') ? 'selected' : ''; ?>>1940</option>
</select>
mickeyunderscore
Forum Contributor
Posts: 129 Joined: Sat Jan 31, 2009 9:00 am
Location: UK
Post
by mickeyunderscore » Mon Feb 02, 2009 5:20 pm
Ah I see now. You need to need to change line 8 so that it reads the $_POST variables, instead of local ones:
Code: Select all
$birthdate = $_POST['birthday'] . "/" . $_POST['birthmonth'] . "/" . $_POST['birthyear'];
And remove line 9.
Have you considered using a loop to output these select boxes on your form? It would save you a lot of typing.
mikes1471
Forum Commoner
Posts: 88 Joined: Sat Jan 24, 2009 3:29 pm
Post
by mikes1471 » Mon Feb 02, 2009 5:27 pm
Wow, so cool, works perfectly now thanks loads, Im not sure i know about loops :S