Jump to content

POST not Inserting data into table


fanboime

Recommended Posts

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?

Link to comment
Share on other sites


            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:
               }
           });              
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.