我已經創建了一個html表單(demo.html)& POST它對php文件(demo1.php)的值。然後,我在MySQL &創建的數據庫在PHP文件(demo1.php)寫的連接代碼,但它提供了以下錯誤PHP MySQL驗證錯誤
警告:mysql_connect()函數[function.mysql-連接]:拒絕訪問用戶「根'@' 本地主機」(使用密碼:是)在C:\ XAMPP \ htdocs中\ demo1.php第8行 錯誤連接到MySQL
<?php
// contact to database
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = 'password';
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');
//$conn = mysql_connect("localhost","root","password") or die ('Error connecting to mysql');
$dbname = 'test';
mysql_select_db($dbname,$conn);
//$connect = mysql_connect("localhost", "root", "pass") or die ("Error , check your server connection.");
//mysql_select_db("test");
//Get data in local variable
$v_name=$_POST['name'];
$v_email=$_POST['email'];
$v_msg=$_POST['msg'];
// check for null values
if ($v_name=="" or $v_msg=="")
echo "All fields must be entered, hit back button and re-enter information";
else{
$query="insert into contact(name,email,msg) values('$v_name','$v_email','$v_msg')";
mysql_query($query) or die(mysql_error());
echo "Your message has been received";
mysql_close($conn);
}
?>
MySQL服務器是否正在運行?你確定用戶名和密碼正確嗎? – TuteC 2011-02-24 05:51:31