fanboime Posted April 27, 2014 Share Posted April 27, 2014 Here is my ajax $(".submit").click(function(){ var vp = $("input#vehicle_plate").val(); var vm = $("input#vehicle_model").val(); var vt = $("input#vehicle_type").val(); var da = $("input#date_acquired").val(); var ad = $("input#assigned_driver").val(); var dataString = 'vehicle_plate='+ vp + '&vehicle_model='+ vm + '&vehicle_type='+ vt + '&date_acquired='+ da + '&assigned_driver='+ ad; $.ajax({ type: "POST", url: "process.php", data: dataString, success: function(){ $('.success').fadeIn(200).show(); $('.error').fadeOut(200).hide(); } }); return false; }); And here is my PHP where i pass my 'dataString' <?PHP include("db.classes.php"); $g = new DB(); $g->connection(); if($_POST) { $vehiclePlate = $g->clean($_POST["vehicle_plate"],1); $vehicleModel = $g->clean($_POST["vehicle_model"],1); $vehicleType = $g->clean($_POST["vehicle_type"]); $assignedDriver = $g->clean($_POST["assigned_driver"],1); $ad = date('Y-m-d', strtotime($_POST["datepicker"])); $g->add($vehiclePlate, $vehicleModel, $vehicleType, $assignedDriver, $ad); } $g->close(); ?> And here is my database query public function add($vehiclePlate, $vehicleModel, $vehicleType, $assignedDriver, $ad) { $sql = "insert into vehicles(`vehicle_plates`,`DA`,`type`, `model`, `driver`) values('$vehiclePlate', '$ad', '$vehicleType', '$vehicleModel', '$assignedDriver')"; if(!mysql_query($sql)) { $this->error = mysql_error(); return true; } else { return false; } } the AJax is succesful but when i try and see the table in my databse the inserted row are al 'Undefined' what seems to be causing this? Quote Link to comment Share on other sites More sharing options...
Strider64 Posted April 27, 2014 Share Posted April 27, 2014 var params = { vehicle_plate: vp, vehicle_model: vm, vehicle_type: vt, date_acquired: da, assigned_driver: ad }; // Set parameters var dataString = jQuery.param( params ); // Set parameters to correct AJAX format $.ajax({ type:"post", url:"process.php", data: dataString, success:function(info){ $('#result').html(info); // Display the result back when saved: } }); Quote Link to comment 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.