在mamp中连接数据库1045时发生错误

时间:2016-07-30 01:58:56

标签: php mysql

我想在数据库中创建表单并链接用户信息,但在mamp"中连接数据库1045时发生链接"错误时遇到问题,

我的先生是MAMP

这是我的表单代码,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 个答案:

答案 0 :(得分:0)

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