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

使用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));
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向