carter delRay Posted June 18, 2015 Share Posted June 18, 2015 I have already created mysql table with data, this is my javascript code <SCRIPT language="JavaScript">function send_status(){var status;var Digital=new Date()var hours=Digital.getHours()if (hours>=6&&hours<8) //on timestatus = "onTime";else if (hours>=8) //late comersstatus = "late";window.alert(status);}$.ajax({type: "POST",url: "ajaxjs.php",data: status,cache: false,success: function(html) {alert(html);}});}return false;}</SCRIPT> im attempting to generate a value for user status from th above if command in js then send this string into my db using ajax which is pointing to my php page <?php// Fetching Values From URL$connection = mysql_connect("localhost", "CJroot", ""); $db = mysql_select_db("mysql_practice", $connection); if (isset($_POST['typeahead'])) {$query = mysql_query("UPDATE user_signin SET status='$status' WHERE user_name = '$typeahead')"); //Insert Queryecho "Form Submitted succesfully";}mysql_close($connection); ?> im not getting it right please any suggestions? Link to comment Share on other sites More sharing options...
justsomeguy Posted June 18, 2015 Share Posted June 18, 2015 If the function is called "send_status", then you probably want that ajax request inside the function. Right now it's not inside the function, so status doesn't have a value.Also, you need to switch your database code to use either the PDO or mysqli extension, not the mysql extension. It's been out of date for over a decade.Your PHP code is also trying to use variables called $status and $typeahead that don't exist. 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now