php 往mysql中插入数据
Add New Record in MySQL Databaseif(isset($_POST['add']))
{
$dbhost = 'localhost:3306';
$dbuser = 'root';
$dbpass = 'root';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn )
{
die('Could not connect to mysql');
}
if(! get_magic_quotes_gpc() )
{
$emp_name = addslashes ($_POST['emp_name']);
$emp_address = addslashes ($_POST['emp_address']);
}
else
{
$emp_name = $_POST['emp_name'];
$emp_address = $_POST['emp_address'];
}
$emp_salary = $_POST['emp_salary'];
$sql = "INSERT INTO employee ".
"(emp_id, emp_name,emp_address, emp_salary) ".
"VALUES(1, '$emp_name','$emp_address',$emp_salary)";
mysql_select_db('test_db');
$retval = mysql_query( $sql, $conn );
if(! $retval )
{
die('Could not enter data: ');
}
echo "Entered data successfully\n";
mysql_close($conn);
}
else
{
?>
Employee Name | |
Employee Address | |
Employee Salary | |
}
?>
分享到:
2012-09-14 19:36
浏览 1349
评论