我正在尝试连接到数据库,它连接成功但无法使用数据库。我对 PHP 的这个概念非常陌生。请帮助我,让我知道我是否在某个地方出错了
<?php
define('DB_NAME', 'bvh');
define('DB_USER', 'root');
define('DB_PASSWORD', '');
define('DB_HOST', 'localhost');
$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
if(!$link){
die('could not connect: '.mysql_error());
}
echo 'Connected Successfully<br>';
$db_selected = mysql_select_db(DB_NAME, $link);
if(!$db_selected){
die('Cannot use '.DB_NAME.':'. mysql_error());
}
$yname=$_POST['yname'];
$faculty=$_POST['faculty'];
$class=$_POST['class'];
$uname=$_POST['uname'];
$email=$_POST['email'];
$pwd=$_POST['pwd'];
$rpwd=$_POST['rpwd'];
$sql = "INSERT INTO students (yname, faculty, class, uname, email, pwd, rpwd) VALUES('$yname', '$faculty', '$class', '$uname', '$email', '$pwd', '$rpwd')";
if(!mysql_query($sql)){
die('Error: ' .mysql_error());
}
mysql_close();
?>