doujie4050
2015-04-19 20:22
浏览 100
已采纳

使用mysqli_connect在PHP中的服务器超时/登录错误

I am new to PHP. I have worked a little before on it , but not much. Now, I have IIS server installed in my machine and it consumes port 80 and for that reason I have changed the wamp server's port to 8080 in the config file.

Now ,what I have is a simple login form.The HTML markup looks like this :

<?php
    session_start();

    if(isset($_REQUEST["error"])){
?>
    <script type="text/javascript">
        alert("Username and/or Password is incorrect!Please try again!");
    </script>        
<?php
    }
 ?>
<html>
<head>
<body>
<form method="post" action="verifyUser.php">

<div class="container">
        <div class="card card-container">
            <!-- <img class="profile-img-card" src="//lh3.googleusercontent.com/-6V8xOA6M7BA/AAAAAAAAAAI/AAAAAAAAAAA/rzlHcD0KYwo/photo.jpg?sz=120" alt="" /> -->
            <img id="profile-img" class="profile-img-card" src="//ssl.gstatic.com/accounts/ui/avatar_2x.png" />
            <p id="profile-name" class="profile-name-card"></p>
            <form class="form-signin">
                <span id="reauth-email" class="reauth-email"></span>

                <input type="email" name="email" id="inputEmail" class="form-control" placeholder="Email address" required autofocus><br>
                <input type="password" name="password" id="inputPassword" class="form-control" placeholder="Password" required>

                <div id="remember" class="checkbox">

                    <label>
                        <input type="checkbox" value="remember-me"> Remember me
                    </label>

                </div>

                <button class="btn btn-lg btn-primary btn-block btn-signin" type="submit">Sign in</button>
            </form><!-- /form -->
            <a href="#" class="forgot-password">
                Forgot the password?
            </a>
            <br>

        </div><!-- /card-container -->
    </div><!-- /container -->

    </form>
 </body>
 </html>

and the PHP file, verifyUser.php looks like this :

<?php
    session_start();

    $email = $_POST["email"];
    $pass = $_POST["password"];

    $con = mysqli_connect("localhost","root","","user",8080)  or die("Some error occurred during connection " . mysqli_error($con));

    $result_row = mysqli_query($con,"select * from info where Email='$email' and Password='$pass'");

    if($row = mysqli_fetch_array($result_row)){
        $_SESSION["existing_user"] = $row['Name'];
        $_SESSION["email"] = $row['Email'];
        header("location : home.php");
    }
    else{
        header("location:form1.php?error=1");
    }
?>

Now when I try to login, I get the error :

Warning: mysqli_connect(): MySQL server has gone away in C:\wamp\www\verifyUser.php on line 7

My error screen looks like this : enter image description here

I have studied this error and tried all the alternatives , which doesn't seem to work.One of them was to make some changes in php.ini file, but doesn't seem to work either!

Can someone tell me why is this actually happening and the solution for it?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dongrong6235 2015-04-19 20:26
    已采纳

    No need to change port, the last argument is for Mysql port which is usually 3306, but 8080 is used by wamp which is totally diffrent from Mysql.

    So this code should work just fine

      $con = mysqli_connect("localhost","root","","user")  or die("Some error occurred during connection " . mysqli_error($con));
    
    点赞 打赏 评论

相关推荐 更多相似问题