We help IT Professionals succeed at work.

posting a javascript variable into a database

amchugh89
amchugh89 asked
on
I need to insert a value (date selected from a javascript calendar) into php

i have php code that inserts a few things into a database:

 mysql_query("INSERT INTO `database`.`table` (field1 ,
field2 ,
field3,
date
)
VALUES ('$_POST[thing_1]','$_POST[thing_2]','$_POST[thing_3]','$_POST[javascript_date ]')");

my query works for thing_1, thing_2 and thing_3, which i have gotten from standard html elements like textboxes and dropdown list - but i am having trouble posting to the 'date' column.
they are all within the same form but...
unlike the other things i posted, javascript_date is selected from a fancy js calendar.

the code for the calendar is given below and the  link to the demo is given at the bottom of
http://javascriptcalendar.org/javascript-date-picker.php

<link rel="stylesheet" type="text/css" media="all" href="jsDatePick_ltr.min.css" />

<script type="text/javascript">
	window.onload = function(){
		
		
		g_globalObject = new JsDatePick({
			useMode:1,
			isStripped:true,
			target:"div3_example"
			/*selectedDate:{				This is an example of what the full configuration offers.
				day:5,						For full documentation about these settings please see the full version of the code.
				month:9,
				year:2006
			},
			yearsRange:[1978,2020],
			limitToToday:false,
			cellColorScheme:"beige",
			dateFormat:"%m-%d-%Y",
			imgPath:"img/",
			weekStartDay:1*/
		});		
		
		g_globalObject.setOnSelectedDelegate(function(){
			var obj = g_globalObject.getSelectedDay();

			document.getElementById("div3_example_result").innerHTML = obj.month + "/" + obj.day + "/" + obj.year;
		});
		



		
	};
</script>
</head>
<body>
	<h3>Choose Date</h3>
    


    <div id="div3_example" style="margin:10px 0 0px 0; border:dashed 1px black; width:205px; height:205px;">
    	
    </div>

    <div id="div3_example_result" style="height:20px; line-height:20px; width:80px; margin:10px 0 20px 0; border:dashed 1px black;"></div>

</body>
</html>

Open in new window

Comment
Watch Question

Web Architect
Commented:
you should use the right format for date :-)

code...
$oldDate = $_POST['javascript_date'];
$newDate = date('Y/m/d', $oldDate); 

mysql_query("INSERT INTO `database`.`table` (field1 ,
field2 ,
field3,
date
)
VALUES ('$_POST[thing_1]','$_POST[thing_2]','$_POST[thing_3]','$newDate')");

Open in new window

Author

Commented:
in my code i posted  what is the variable - i called it javascript_date, but i dont know what the actual variable im dealing with is im just assuming its in the js code i posted

Author

Commented:
nvm got it to work

Author

Commented:
thnx