import syeef.com.*;
public class PHP {
//

Basic MySQL Insert Query with PHP

This example shows how to do basic MySQL Insert Query with PHP:


$server = "localhost"; // MySQL server address
$user = "root"; // MySQL user name
$pass = "1234"; // MySQL user password
$database = "my_database"; // name of your database

$mysql = @mysql_connect($server, $user, $pass)
or die("Could not connect to MySQL server");

@mysql_select_db($database)
or die("Could not connect to MySQL database");

// now let us perform a simple INSERT query
// my_table has 2 fields, id(int) and name(varchar)
$query = @mysql_query('INSERT INTO my_table (id, name)
VALUES (1, "My Name")');

if ($query) { // success
echo "Success!";
} else {
echo "Failed :(";
}

@mysql_close($mysql); // close MySQL connection
}