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

报告相同问题?

悬赏问题

  • ¥150 HDMI分路器LT86102 的输出在890MHz频点处EMC超标8DB
  • ¥36 如何安全的迁移用户C盘用户文件(戴尔电脑)
  • ¥15 druid(相关搜索:数据库|防火墙)
  • ¥15 大一python作业
  • ¥15 preLaunchTask"C/C++: aarch64- apple-darwin22-g++-14 生成活动 文件”已终止,退出代码为-1。
  • ¥60 如何鉴定微信小程序数据被篡改过
  • ¥18 关于#贝叶斯概率#的问题:这篇文章中利用em算法求出了对数似然值作为概率表参数,然后进行概率表计算,这个概率表是怎样计算的呀
  • ¥20 C#上传XML格式数据
  • ¥15 elementui上传结合oss接口断点续传,现在只差停止上传和继续上传,各大精英看下
  • ¥20 手机截图相片分辨率降低一半