插入PHP表

时间:2013-12-16 10:27:17

标签: php mysql

<?php
    $username = "root";
$password = "root";
$hostname = "localhost"; 

//connection to the database
$con = mysql_connect($hostname, $username, $password) 
or die("Unable to connect to MySQL");
echo "Connected to MySQL<br>";
$ID = "";
$user_name = $_POST['user_name'];
$hash_pass = md5($_POST['user_password']);
$Email = $_POST['user_email'];

echo $user_name;

echo $hash_pass;

echo $Email;
$sql="INSERT INTO BibleCheck (Username, Password, Email)
VALUES
('$_POST['user_name']','md5($_POST['user_password'])','$_POST['user_email']')";

if (!mysqli_query($con,$sql))
{
die('Error: ' . mysqli_error($con));
}
echo "1 record added";



?>

我写了这个,我收到了一个错误......

它连接到数据库就好了,怎么没有插入到表中,它会产生一个未知的错误

1 个答案:

答案 0 :(得分:3)

您正在使用mysql_connect()进行连接。

然后使用mysqli_query()执行错误的查询。

您正在连接数据库。

使用此行进行连接:

mysqli_connect("myhost","myuser","mypassw","mybd");