Lisa23 Posted September 25, 2010 Share Posted September 25, 2010 Hi i have a drop down menu for date which is meant to insert all 3 values into a date column bt is only sending the year how can i fix it <select name="date_of_birth"> <option value="1">January <option value="2">February <option value="3">March <option value="4">April <option value="5">May <option value="6">June <option value="7">July <option value="8">August <option value="9">September <option value="10">October <option value="11">November <option value="12">December </select> <select name="date_of_birth"> <option value="1">1 <option value="2">2 <option value="3">3 <option value="4">4 <option value="5">5 <option value="6">6 <option value="7">7 <option value="8">8 <option value="9">9 <option value="10">10 <option value="11">11 <option value="12">12 <option value="13">13 <option value="14">14 <option value="15">15 <option value="16">16 <option value="17">17 <option value="18">18 <option value="19">19 <option value="20">20 <option value="21">21 <option value="22">22 <option value="23">23 <option value="24">24 <option value="25">25 <option value="26">26 <option value="27">27 <option value="28">28 <option value="29">29 <option value="30">30 <option value="31">31 </select> <select name="date_of_birth" id="year"> <?php $year = date("Y"); for($i=$year;$i>$year-50;$i--) { if($year == $i) echo "<option value='$i' selected>Current Year</option>"; else echo "<option value='$i'>$i</option>"; } ?> Link to comment https://forums.phpfreaks.com/topic/214331-drop-dow-list-for-date-only-inserts-year-into-database/ Share on other sites More sharing options...
kenrbnsn Posted September 25, 2010 Share Posted September 25, 2010 Fix your form. You're using the same name for each input, so only the last value is sent. Use different names. Ken Link to comment https://forums.phpfreaks.com/topic/214331-drop-dow-list-for-date-only-inserts-year-into-database/#findComment-1115350 Share on other sites More sharing options...
Lisa23 Posted September 25, 2010 Author Share Posted September 25, 2010 yeah but then how do i sent into column because i have like this mysql insert '$_POST[date_of_birth]' do i change that to what if all three will have different names??? i want all all to go into same column cz thers the month year and date id i give differnt name how do i make it all go into same column??? Link to comment https://forums.phpfreaks.com/topic/214331-drop-dow-list-for-date-only-inserts-year-into-database/#findComment-1115351 Share on other sites More sharing options...
kenrbnsn Posted September 25, 2010 Share Posted September 25, 2010 You would concatenate the POSTed values in the query. For example, in your form: <?php $months = array('','January','February','March','April','May','June','July','August','September','October','November','December'); echo '<select name="month_of_birth">'; for ($i=1;$i<13;++$i) { echo '<option value="' . sprintf("%02d",$i) . '">' . $months[$i] . '</option>'; } echo '</select>'; echo '<select name="day_of_birth">'; for ($i=1;$i<32;++$i) { echo '<option value="' . sprintf("%02d",$i) . '">' . $i . '</option>'; } echo '</select>'; echo '<select name="year_of_birth">'; $year = date("Y"); for ($i = $year;$i > $year-50;$i--) { $s = ($i == $year)?' selected':''; echo '<option value="' . $i . '" ' . $s . '>' . $i . '</option>'; } ?> Then in your processing script: <?php $date_of_birth = $_POST['year_of_birth'] . '-' . $_POST['month_of_birth'] . '-' . $_POST['day_of_birth']; $q = "insert into tbl set column_name = '$date_of_birth'"; ?> Note: syntax not checked for errors. Ken Link to comment https://forums.phpfreaks.com/topic/214331-drop-dow-list-for-date-only-inserts-year-into-database/#findComment-1115357 Share on other sites More sharing options...
Lisa23 Posted September 25, 2010 Author Share Posted September 25, 2010 sorry but my insert method is like this so i dnt really know how to implement urs into it?? mine mysql_query("INSERT INTO driversnew (id, name, location, date_of_birth, car_number, favourite_track, least_favourite_track, achievements, sponsors, email, image, display) VALUES ('$_POST[id]', '$_POST[name]', '$_POST[location]','$_POST[date_of_birth]','$_POST[date_of_month]','$_POST[date_of_year]','$_POST[car_number]','$_POST[favourite_track]', '$_POST[least_favourite_track]','$_POST[achievements]', '$_POST[sponsors]','$_POST[email]', '$image_name','0')"); } yours <?php $date_of_birth = $_POST['year_of_birth'] . '-' . $_POST['month_of_birth'] . '-' . $_POST['day_of_birth']; $q = "insert into tbl set column_name = '$date_of_birth'"; ?> Link to comment https://forums.phpfreaks.com/topic/214331-drop-dow-list-for-date-only-inserts-year-into-database/#findComment-1115360 Share on other sites More sharing options...
kenrbnsn Posted September 25, 2010 Share Posted September 25, 2010 Mine was just an example, since I didn't know yours. Here's yours with my example: <?php $date_of_birth = $_POST['year_of_birth'] . '-' . $_POST['month_of_birth'] . '-' . $_POST['day_of_birth']; $q = "INSERT INTO driversnew (id, name, location, date_of_birth, car_number, favourite_track, least_favourite_track, achievements, sponsors, email, image, display) VALUES ('$_POST[id]', '$_POST[name]', '$_POST[location]','$date_of_birth','$_POST[car_number]','$_POST[favourite_track]', '$_POST[least_favourite_track]','$_POST[achievements]', '$_POST[sponsors]','$_POST[email]', '$image_name','0')"; $rs = mysql_query($q) or die("Problem with the query: $q<br>" . mysql_error()); ?> BTW, you really should be validating the input from your form, or you will run into problems. Ken Link to comment https://forums.phpfreaks.com/topic/214331-drop-dow-list-for-date-only-inserts-year-into-database/#findComment-1115364 Share on other sites More sharing options...
Lisa23 Posted September 25, 2010 Author Share Posted September 25, 2010 it post everything except the date??? Link to comment https://forums.phpfreaks.com/topic/214331-drop-dow-list-for-date-only-inserts-year-into-database/#findComment-1115366 Share on other sites More sharing options...
kenrbnsn Posted September 25, 2010 Share Posted September 25, 2010 Like I said "syntax not checked for errors" -- I left out the "</select>" tag at the end of the last <select>. When I have trouble getting data from form, I put <?php echo '<pre>' . print_r($_POST,true) . '</pre>'; ?> at the start of the processing script. This will show the data that your form is sending. It can be very helpful. Ken Link to comment https://forums.phpfreaks.com/topic/214331-drop-dow-list-for-date-only-inserts-year-into-database/#findComment-1115371 Share on other sites More sharing options...
Lisa23 Posted September 25, 2010 Author Share Posted September 25, 2010 this come up bt still doenst sent date Array ( [name] => phpfreaks [location] => uyfuy [month_of_birth] => 01 [day_of_birth] => 01 [year_of_birth] => 2010 [car_number] => carnumber [favourite_track] => uyf [least_favourite_track] => [achievements] => [sponsors] => => [email protected] [verif_box] => 4342 [submit] => Submit ) Link to comment https://forums.phpfreaks.com/topic/214331-drop-dow-list-for-date-only-inserts-year-into-database/#findComment-1115375 Share on other sites More sharing options...
kenrbnsn Posted September 25, 2010 Share Posted September 25, 2010 Can you show us you mysql insert statement? Ken Link to comment https://forums.phpfreaks.com/topic/214331-drop-dow-list-for-date-only-inserts-year-into-database/#findComment-1115377 Share on other sites More sharing options...
Lisa23 Posted September 25, 2010 Author Share Posted September 25, 2010 $q = "INSERT INTO driversnew (id, name, location, date_of_birth, car_number, favourite_track, least_favourite_track, achievements, sponsors, email, image, display) VALUES ('$_POST[id]', '$_POST[name]', '$_POST[location]','$date_of_birth','$_POST[car_number]','$_POST[favourite_track]', '$_POST[least_favourite_track]','$_POST[achievements]', '$_POST[sponsors]','$_POST', '$image_name','0')"; $rs = mysql_query($q) or die("Problem with the query: $q<br>" . mysql_error()); and the form <?php $months = array('','January','February','March','April','May','June','July','August','September','October','November','December'); echo '<select name="month_of_birth">'; for ($i=1;$i<13;++$i) { echo '<option value="' . sprintf("%02d",$i) . '">' . $months[$i] . '</option>'; } echo '</select>'; echo '<select name="day_of_birth">'; for ($i=1;$i<32;++$i) { echo '<option value="' . sprintf("%02d",$i) . '">' . $i . '</option>'; } echo '</select>'; echo '<select name="year_of_birth">'; $year = date("Y"); for ($i = $year;$i > $year-50;$i--) { $s = ($i == $year)?' selected':''; echo '<option value="' . $i . '" ' . $s . '>' . $i . '</option>'; } echo '</select>'; ?> Link to comment https://forums.phpfreaks.com/topic/214331-drop-dow-list-for-date-only-inserts-year-into-database/#findComment-1115379 Share on other sites More sharing options...
kenrbnsn Posted September 25, 2010 Share Posted September 25, 2010 Did you put this line before the query: <?php $date_of_birth = $_POST['year_of_birth'] . '-' . $_POST['month_of_birth'] . '-' . $_POST['day_of_birth']; ?> Put an <?php echo $q . "<br>"; ?> and see what is displayed. Ken Link to comment https://forums.phpfreaks.com/topic/214331-drop-dow-list-for-date-only-inserts-year-into-database/#findComment-1115382 Share on other sites More sharing options...
Lisa23 Posted September 25, 2010 Author Share Posted September 25, 2010 yeah i have that line this what comes up $date_of_birth = $_POST['year_of_birth'] . '-' . $_POST['month_of_birth'] . '-' . $_POST['day_of_birth']; INSERT INTO driversnew (id, name, location, date_of_birth, car_number, favourite_track, least_favourite_track, achievements, sponsors, email, image, display) VALUES ('', 'tv', 'location','2010-01-01','carnumber','', '','', '','[email protected]', '','0') Link to comment https://forums.phpfreaks.com/topic/214331-drop-dow-list-for-date-only-inserts-year-into-database/#findComment-1115383 Share on other sites More sharing options...
kenrbnsn Posted September 25, 2010 Share Posted September 25, 2010 Your query has the correct information in the correct place. Why do you think it's not being inserted? Ken Link to comment https://forums.phpfreaks.com/topic/214331-drop-dow-list-for-date-only-inserts-year-into-database/#findComment-1115385 Share on other sites More sharing options...
Lisa23 Posted September 25, 2010 Author Share Posted September 25, 2010 i have this line do u think i need to modify in a way too?? $date_of_birth = stripslashes($date_of_birth); Link to comment https://forums.phpfreaks.com/topic/214331-drop-dow-list-for-date-only-inserts-year-into-database/#findComment-1115386 Share on other sites More sharing options...
kenrbnsn Posted September 25, 2010 Share Posted September 25, 2010 No. The stripslashes function will only affect variable whose values contain a backslash. It might be best to post what your code currently looks like. Also post the format of your database table, as there could be a problem with the datatype of the "date_of_birth" column. I assumed it is a DATE type. Ken Link to comment https://forums.phpfreaks.com/topic/214331-drop-dow-list-for-date-only-inserts-year-into-database/#findComment-1115392 Share on other sites More sharing options...
Lisa23 Posted September 25, 2010 Author Share Posted September 25, 2010 ok is posting now but i have this echo back to display bck but it doesnt display back the date echo "<td>" . $_POST['date_of_birth'] . "</td>"; and also this one that send to email doesnt display the date on the email $message = " Name: $name \n Link to comment https://forums.phpfreaks.com/topic/214331-drop-dow-list-for-date-only-inserts-year-into-database/#findComment-1115398 Share on other sites More sharing options...
kenrbnsn Posted September 25, 2010 Share Posted September 25, 2010 There is no "date_of_birth" in the $_POST array. You would have to echo the variable $date_of_birth instead. Probably the same for the email message. Ken Link to comment https://forums.phpfreaks.com/topic/214331-drop-dow-list-for-date-only-inserts-year-into-database/#findComment-1115401 Share on other sites More sharing options...
Lisa23 Posted September 25, 2010 Author Share Posted September 25, 2010 on the email i have like this still doesnt wrk $message = " DoB: $date_of_birth \n Email: $email \n"; ohh and on the form is how do i keep the date after refresh i know how to do on a normal input text but on tha form is it possible?? Link to comment https://forums.phpfreaks.com/topic/214331-drop-dow-list-for-date-only-inserts-year-into-database/#findComment-1115403 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.