Sample Data insertion in sql using ajax

<?php 
include 'dbConnection.php';

$sql = "INSERT INTO students (name,email,password) 
        VALUES 
        ('Donald','sample@sample.com,','adf'),
        ('Trump','sample@sample.com,','dfg'),
        ('Vladmir','sample@sample.com,','ddd'),
        ('Putin','sample@sample.com,','fgh'),
        ('Papa','sample@sample.com,','dfg'),
        ('Johnson','sample@sample.com,','fvb')";

the above is a sample.php file.

when a button clicks Insert sample data. I want to insert sample data into the MYSQL table.

AJAX Code:

// Insert Sample data
	$("#sample").click(function(e) {
		e.preventDefault();
		$.ajax({
			url:"sample.php",
			method:"POST",
			data: JSON.stringify(mydata),
			success: function(data){
				showData();
			},
		});		
	}

But nothing is happening

On click in the URL ends ? is appearing.

Well for starters, my javascript console tells me you’ve got a syntax error in your javascript. And it’s right. Count your parentheses and tell me where you’ve goofed.

1 Like

BTW there’s no need to stringify the data; on the contrary, for most practical purposes it’s easier to have jQuery encode the data and send it as application/x-www-form-urlencoded – otherwise you’ll also have to set the headers accordingly.

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.