Here is my button
$( "#editVehicle" ).button().click(function( event ) {
event.preventDefault();
var vp = $("input[name=vehicle_plate]").val();
var dataString = 'vehicle_plate='+ vp;
$.ajax({
type: "POST",
url: "editvehicle.php",
data: dataString,
success: function(){
alert("Success!");
}
});
});
Here is my PHP
<?PHP
include("db.classes.php");
$g = new DB();
$g->connection();
if($_POST)
{
$vehiclePlate = $g->clean($_POST["vehicle_plate"],1);
$g->edit($vehiclePlate);
}
$g->close();
?>
And here is my db.classes
public function edit($vehiclePlate)
{
$sql = "select vehicle_name from vehicles where vehicle_plate='$vehiclePlate'";
$result = mysql_query($sql);
$row = mysql_fetch_array($result);
echo "<script>
$(\"input[name=vehicle_model]\").val(".$row['vehicle_name'].");
</script>
";
}
There is an input field in my html where i input the vehicle plate then when the user clicks the button the program searches the database for the vehicle name with the plate the user entered and returns the value to another inputfield named "vehicle_name". Any idea on where am i going wrong here?