Jump to content

my php script saves date 0000-00-00 into mysql database


smitagodbole

Recommended Posts

Hi

I don't know exactly what to do to see correct date of birth into my sql database.  I have following code i.e.

$month=$_POST['month'];

$year=$_POST['year'];

$date=$_POST['date'];

$date_value="$month/$date/$year";

echo"YYYY-mm-dd format:$date_value";

 

and sql insert statement is like this

$sql = "INSERT INTO table_name(fname, lname, gender, add1, add2, city, state, zip, country, email, phone, cellphone, dob, photo1)

VALUES('$fname','$lname','$gender','$add1','$add2','$city','$state','$zip','$country','$email','$phone','$cellphone',

'$date_value','" . $image['name'] . "')";

 

I don't know what exactly I need to do?  Even though I changed the setting in php ini  to register_globals = On

I would appreciate any kind of help regarding this matter.

Thanks

Smita

 

First, go back and change register_globals back to off. It has nothing to do with this problem. Then, post the html for the form fields that collect the information for the date.

I changed the setting in php ini  to register_globals = On

 

^^^ Why on earth did you do that. That setting has absolutely nothing to do with the format of your date, especially since you echo the date you build and it is probably what you expect (though it is not what mysql expects.)

 

Mysql date data types are formatted YYYY-MM-DD. Don't you suppose that you would need to get your date value into that format in order to be able to store it without error?

Here is my html script and I did change my insert script to

$date_value="$year/$month/$dt";

<select name="year" ></th>

<option>Year</option>

<option>1970</option><option>1971</option><option>1972</option><option>1973</option><option>1974</option><option>1975</option><option>1976</option><option>1977</option><option>1978</option><option>1979</option><option>1980</option><option>1981</option><option>1982</option><option>1983</option><option>1984</option><option>1985</option><option>1986</option><option>1987</option><option>1988</option><option>1989</option><option>1990</option><option>1991</option><option>1992</option>

</select>

<select size="1" name="month"></th>

<option>select month</option>

<option>January</option><option>February</option><option>March</option><option>April</option><option>May</option><option>June</option><option>July</option><option>August</option><option>September</option><option>October</option><option>November</option><option>December</option>

<option value='01'>January</option><option value='02'>February</option><option value='03'>March</option><option value='04'>April</option><option value='05'>May</option><option value='06'>June</option><option value='07'>July</option><option value='08'>August</option><option value='09'>September</option><option value='10'>October</option><option value='11'>November</option><option value='12'>December</option>

</select>

<select size="1" name="date" ></th>

<option>Date</option>

<option>1</option><option>2</option><option>3</option><option>4</option><option>5</option><option>6</option><option>7</option><option>8</option><option>9</option><option>10</option><option>11</option><option>12</option><option>13</option><option>14</option><option>15</option><option>16</option><option>17</option><option>18</option><option>19</option><option>20</option><option>21</option><option>22</option><option>23</option><option>24</option><option">25</option><option>26</option><option>27</option><option>28</option><option>29</option><option>30</option><option>31</option>

</select>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.