Ok I have a problem here. I'm trying to get a JS variable to use in an sql query. Now i know that's not possible so i passed the variable using jquery and use the get method to assign it to a variable in php. But the php alwways loads before JS so the sql query doesn't update. Here's there code:
var monthS = calenderMonths[monthNow];
$.get('load2.php', {location:monthS} );
This is in my JS file in a function that's being onloaded in HTML
This is my php:
$monthS = $_GET['location'];
echo "alert($monthS);";
// Connect to MySQL
if ( !( $database = mysql_connect( "localhost",
"root", "" ) ) )
die( "Could not connect to database </body></html>" );
// open Events database
if ( !mysql_select_db( "Events", $database ) )
die( "Could not open Events database </body></html>" );
$result = mysql_query("SELECT * FROM posted_events WHERE Month_ = '$monthS' ")
or die ('Error updating database because: '.mysql_error());
I alert $monthS to see if it passed but the alert ends up empty at first but after clicking 'ok' like 3 secs another alert box comes up with the variable. So I believe the PHP is loading before the variable gets passed. Is there anyway i could solve this? Thanks