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

报告相同问题?

悬赏问题

  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集