We help IT Professionals succeed at work.
Get Started

passing javascript variable from form to php/mySQL database

amchugh89
amchugh89 asked
on
739 Views
Last Modified: 2013-12-12
i am totally banging my head against the wall on this one.


everything works except it doesnt pass the date from javascript to php (or at least to mySQL).
 the mySQL game_date just says '0000-00-00, 1969-12-31 or 2069-12-31'   even though js the calendar shows the correct date on the screen.

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

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

<script type="text/javascript" src="jsDatePick.min.1.3.js"></script>

<script type="text/javascript">
	window.onload = function(){
		
		
		g_globalObject = new JsDatePick({
			useMode:1,
			isStripped:true,
			target:"div3_example"

		});		

		g_globalObject.setOnSelectedDelegate(function(){
			var obj = g_globalObject.getSelectedDay();
			document.getElementById("div3_example_result").innerHTML = obj.month + "/" + obj.day + "/" + obj.year;
		});
	};
</script>

</head>

<style type="text/css" media="all">
       body
{
	background: #D96F2D;
	height: 100%;
	font-family: Verdana, Geneva, Arial, Helvetica, sans-serif;
	font-size: 12px;
    <body>
    </style>
<form action="<?php echo $_SERVER['PHP_SELF']?>" method="post">
<BR>
<BR>

<BR>
<BR>
Game Name: <br> <br>   <input type="text" name="Game_Name" size="25">  <br> <br>
Location: <br>  <br> <input type="text" name="Game_Location" size="35">
 <br><br>
Details:<BR> <br>
<TEXTAREA NAME="game_description" COLS=40 ROWS=6></TEXTAREA>

<br><br>

       Time:  <br>   <br>  <input type="varchar" name="game_time" size="8">  <BR>  <br>
                 [b] <div id="div3_example"  style="margin:10px 0 0px 0; border:dashed 1px black; width:205px; height:205px;">
    </div>
    <div id="div3_example_result" name ="div3_example_result" style="height:20px; line-height:20px; width:80px; margin:10px 0 20px 0; border:dashed 1px black;"></div>[/b]

 Category: <br>    <br>
<select name="cats">
       <option value="1">football</option>
       <option value="2">basketball</option>
<option value="3">soccer</option>
       <option value="4">baseball</option>
       <option value="5">hockey</option>
</select>  <br><br>

<P><INPUT TYPE=SUBMIT VALUE="submit">
</FORM>

<?php
$con = mysql_connect("localhost","amchugh89","keikolucky1");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
mysql_select_db("gamesDC", $con);

         $cats = isset($_POST['cats']) ? $_POST['cats'] : 'football';

            
//here i am trying to convert the js variable to a php one - the reason for the whole $newer_ $older_date thing is because i have to reformat the js date from m-d-y to the mySQL standard of y-m-d 

 [b] $older_date = $_POST['div3_example_result'];

                      $newer_date = date('y/m/d',  $older_date);
    echo  "$newer_Date";[/b]

  mysql_query("INSERT INTO `gamesdc`.`games` (game_name ,
game_description ,
game_location,
game_time,
[b]game_date,[/b]
game_type
)
VALUES ('$_POST[game_Name]','$_POST[game_description]','$_POST[game_Location]','$_POST[game_time]',[b]'$newer_date',[/b]'".$cats."')");

    mysql_close($con);
?>

Open in new window


All the bold stuff is what i am assuming doesnt work (it is the code related to what is f***ed  up
Comment
Watch Question
Commented:
This problem has been solved!
Unlock 1 Answer and 5 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE