mrbambrick Posted April 26, 2014 Share Posted April 26, 2014 Hello All, I have the following jQuery script that I would like to post to my mysql database with php. How would I go about getting this information to post to the database? Here is what I have so far. Thank you in advance. <script> $(document).ready(function () { //we want to intialze the valuesvalues = {};values['vehicle'] = "car";values['gender'] = "male";values['age'] = "25";values['position'] = "manager"; //we need to handle the image clicks$("#car, #bus, #train, #boat, #plane, #man, #woman, #25, #35, #45, #55, #manager, #director, #president, #CXO").click(function (event) {event.preventDefault(); //we want to know what row we are dealing withvar imageclass = $(this).attr('class'); //we need all of the other images in the row turned to not selected$("." + imageclass).each(function() {if ($(this).id != event.target.id){var src = $(this).attr('src');if (src.indexOf("2") >= 0){$(this).attr('src', src.replace("2.png", ".png"));}}}); setImageAsSelected(event.target.id);}); function setImageAsSelected(id) {var current = $("#" + id).attr('src');var next;if (current.indexOf("2") < 0) {next = current.replace(".png", "2.png");}$("#" + id).attr('src', next);values[$("#" + id).attr('class')] = id;} //we need to handle the go click$("#go").click(function () {var sql = "INSERT INTO TABLE (Vehicle, Gender, Age, Positon) VALUES ('" + values['vehicle'] + "', '" + values['gender'] + "', '" + values['age'] + "','" + values['position'] + "');";alert(sql);}); }); </script> Quote Link to comment https://forums.phpfreaks.com/topic/288041-post-to-php-with-jquery/ Share on other sites More sharing options...
fastsol Posted April 26, 2014 Share Posted April 26, 2014 Check this tutorial out https://www.youtube.com/watch?v=-EHbBHm5l4g Quote Link to comment https://forums.phpfreaks.com/topic/288041-post-to-php-with-jquery/#findComment-1477374 Share on other sites More sharing options...
mrbambrick Posted April 26, 2014 Author Share Posted April 26, 2014 I did watch that, still not working. Quote Link to comment https://forums.phpfreaks.com/topic/288041-post-to-php-with-jquery/#findComment-1477382 Share on other sites More sharing options...
fastsol Posted April 26, 2014 Share Posted April 26, 2014 Ummm, well it shows you exactly how to use jquery to send data to a php script for processing. What is your updated code after watching the video and implementing the post/ajax request and what is your php code for the db insert? You're not really telling us anything by saying it still doesn't work. Also it's not a good thing to place the sql string in the jquery code for the world to see. Especially if you are literally taking that sql string and passing it to a query command. Literally anyone could change that sql string and do literally anything they wanted on your server, very very very bad thing. Quote Link to comment https://forums.phpfreaks.com/topic/288041-post-to-php-with-jquery/#findComment-1477383 Share on other sites More sharing options...
maelish Posted April 26, 2014 Share Posted April 26, 2014 When you say not working, are you getting errors? Quote Link to comment https://forums.phpfreaks.com/topic/288041-post-to-php-with-jquery/#findComment-1477384 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.