2016-07-30 21 views
0

与数据库1045连接我想创建数据库的表单和链路用户信息,但面对一个问题,当一个链接“而甲基苯丙胺与数据库1045连接时出错”,发生错误而为毫安

我sirver是甲基苯丙胺

这是我的表单代码,是的index.php文件格式和connect.php的代码连接与MySQL 的index.php

<?php 

include("connect.php"); 
if (isset($_POST['submit'])) 
{ 

$firstName =$_POST['fname']; 
$lastName =$_POST['lname']; 
$email =$_POST['email']; 
$password =$_POST['password']; 
$passwordCOnfirm =$_POST['passwordCOnfirm']; 
$image =$_FILES['image']['name']; 
$tmp_image =$_FILES['image']['tmp_name']; 
$imageSize=$_FILES['image']['size']; 

} 

?> 

<!doctype html> 

<html> 
<head> 
    <title>regestration Page</title> 
    <link rel="stylesheet" href="css/styles.css"/> 
</head> 
<body> 

    <div id="wrapper"> 

<div id="#formDiv"> 

    <form method="POST" action ="index.php" enctype="multipart/form-data"> 
      <label>First Name </label><br/> 

     <input type="text" name="fname"/><br/><br/> 

      <label>last Name </label><br/> 
    <input type="text" name="lname"/><br/><br/> 

     <label>Email </label><br/> 
    <input type="text" name="email"/><br/><br/> 

     <label>Password </label><br/> 
     <input type="password" name="password"/><br/><br/> 
     <label>Password Confirm </label><br/> 

     <input type="$passwordCOnfirm" name="$passwordCOnfirm"/><br/><br/> 

      <label>Image </label><br/> 
     <input type="file" name="image"/><br/><br/> 


     <input type="submit" name="submit"/> 

    </form> 
</div> 

    </div> 

</body> 
</html> 

connect.php

<?php 

    $con = mysqli_connect("localhost","root","root","registration"); 

    if(mysqli_connect_errno()) 
    { 
     echo "Error occured while connecting with database ".mysqli_connect_errno(); 
    } 


?> 
+1

你是否在谷歌你的错误号码?这里有一个我发现http://stackoverflow.com/questions/3532868/mysql-error-1045-access-denied - 你可以进一步研究“错误1045 mysqli连接”。还有更多。 –

+0

您是否以root/root身份确认用户名/密码 – C2486

回答

0

如果您确定您的MySQL数据库正在运行,并且您的用户名和密码正确,那么您应该尝试连接到主机127.0.0.1而不是'localhost',它被解释为'套接字'连接。