Write PHP Script to insert data into STUDENT TABLE with fields (roll,first_name,Last_name,city,contact,gender).

Recommended Answers

All 2 Replies

Something like this:


// Connect to the database and create a MySQL resource handler
$mysqli = new mysqli("localhost", "my_user", "my_password", "world");

// Get variables from a form submission, and escape them so they'll be prepped to use in a database query
// and not at risk of an SQL injection attack

$first_name = $mysqli->real_escape_string($_POST['first_name']);
$last_name = $mysqli->real_escape_string($_POST['last_name']);
$city = $mysqli->real_escape_string($_POST['city']);

// Build the SQL string
$sql = "
    INSERT INTO student_table
        first_name = '$first_name',
        last_name = '$last_name',
        city = '$city'

// Execute the query
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.