Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

date not inserting into db 2

Status
Not open for further replies.

dugen

Programmer
Jun 16, 2003
59
US
Hi,

I am using a javascript date picker on a form. When the user selects a date it is displayed in a text box. Right now when the form is submitted the date is not being inserted into the database.

Here is the code for the textbox:

<div name="date" type="text" id="myDatePickerDiv"></div>


Here is the Handle Code:

$date = mysql_real_escape_string($_POST["date"]);

$query = mysql_query("INSERT INTO test (`date`) VALUES ('$date')");


THanks,
 
you need to make sure that the date is received in the form "YYYY-MM-DD".

if it is not, you will need to transform the date. take a look at date() and strtotime() to assist.
 
You are also probably running into problems with the way your query is written. In PHP, the ' and " symbols have distinct meanings and with where you have the ' symbol, your variable is not being interpreted (look here for a detailed explanation). Try this instead:

Code:
$sql = "INSERT INTO test (`date`) VALUES ('" . $date . "')";
$query = mysql_query($sql);
 
I am using a datepicker and the format is in the date format for mysql yyyy-mm-dd.


This is the code that makes the date picker appear:

<div id="myDatePickerDiv">
</div>

How would i pass the value of the date picker to a hidden field?
 
Hi

dugen said:
<div name="date" type="text" id="myDatePickerDiv"></div>
That is invalid HTML.
dugen said:
<div id="myDatePickerDiv">
</div>
That is irrelevant HTML.
dugen said:
How would i pass the value of the date picker to a hidden field?
Depends on the date picker.
Code:
document.[green][i]theform[/i][/green].date.value=[red]datepickerobject.getDate()[/red];

I assume you use a free date picker found on the web. Could you tell us which ? So we can read at least its documentation. Sorry, but your explanations does not reveal useful details.

Even better, could we see the page on-line where you implemented the date picker ?

Feherke.
 
@jet042
the query syntax that the OP posted was correct.
 
THanks for the responses.

I ended up going with a different date picker named tigra. The tigra calendar is a pop up and when a date is selected its value goes into a text box on the form. That value can then be passed to the database with no extra steps.

The date picker i was originally using was BS_DatePicker which opens directly on the form.
 
Hi

Honestly, both code looks kind of amateurish to me.

Personally I would insist on BS_DatePicker or something similar, because works faster, is more ergonomic and some outstandingly stupid pop-up blockers will not break it.

Feherke.
 
I agree with feherke as to tigra. I have not used the other one. many js frameworks come with datepicker widgets. or just build your own.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top