php - Mysql数据库警告

标签 php mysql database

所以我为我的页面创建了注册,点击“提交”按钮后出现了这个错误……我已经创建了 mysql 表,但我不知道为什么会显示这个错误…… 错误:

Warning: mysqli_connect(): (HY000/2013): Lost connection to MySQL server at 'reading initial communication packet', system error: 95 "Operation not supported" in /home/u771616840/public_html/FreeDay/PHP Form 2/configdb.php on line 2

数据库错误

注册码:

    <?php
session_start();
include('configdb.php');
if(isset($_POST['submit']))
{
 //whether the username is blank
 if($_POST['username'] == '')
 {
  $_SESSION['error']['username'] = "User Name is required.";
 }
 //whether the email is blank
 if($_POST['email'] == '')
 {
  $_SESSION['error']['email'] = "E-mail is required.";
 }
 else
 {
  //whether the email format is correct
  if(preg_match("/^([a-zA-Z0-9])+([a-zA-Z0-9._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9._-]+)+$/", $_POST['email']))
  {
   //if it has the correct format whether the email has already exist
   $email= $_POST['email'];
   $sql1 = "SELECT * FROM user WHERE email = '$email'";
   $result1 = mysqli_query($mysqli,$sql1) or die(mysqli_error());
   if (mysqli_num_rows($result1) > 0)
            {
    $_SESSION['error']['email'] = "This Email is already used.";
   }
  }
  else
  {
   //this error will set if the email format is not correct
   $_SESSION['error']['email'] = "Your email is not valid.";
  }
 }
 //whether the password is blank
 if($_POST['password'] == '')
 {
  $_SESSION['error']['password'] = "Password is required.";
 }
 //if the error exist, we will go to registration form
 if(isset($_SESSION['error']))
 {
  header("Location: index.php");
  exit;
 }
 else
 {
  $username = $_POST['username'];
  $email = $_POST['email'];
  $password = $_POST['password'];
  $com_code = md5(uniqid(rand()));

  $sql2 = "INSERT INTO user (username, email, password, com_code) VALUES ('$username', '$email', '$password', '$com_code')";
  $result2 = mysqli_query($mysqli,$sql2) or die(mysqli_error());

  if($result2)
  {
   $to = $email;
   $subject = "Confirmation from TutsforWeb to $username";
   $header = "TutsforWeb: Confirmation from TutsforWeb";
   $message = "Please click the link below to verify and activate your account. rn";
   $message .= "http://www.yourname.com/confirm.php?passkey=$com_code";

   $sentmail = mail($to,$subject,$message,$header);

   if($sentmail)
            {
   echo "Your Confirmation link Has Been Sent To Your Email Address.";
   }
   else
         {
    echo "Cannot send Confirmation link to your e-mail address";
   }
  }
 }
}
?>

配置文件:

<?php
 $mysqli=mysqli_connect('localhost','dbusername','dbpassword','databasename') or die("Database Error");
?>

感谢帮助:)

最佳答案

我想分享我对这个问题的解决方案...MySQL 显示此错误是因为我有错误的表类型...在 register.php 中如下:

 $username = $_POST['username'];
  $email = $_POST['email'];
  $password = $_POST['password'];
  $com_code = md5(uniqid(rand()));

因此您必须在您的表格中创建以下内容...表格的第一行必须是用户名,第二行是电子邮件,然后是密码和 com_code。你不能给他们其他名字,因为你已经在你的 php 文件中定义了这个表名...... 如果这没有帮助,那么请检查您的数据类型是否正确...密码是 INT 而文本只是 TEXT

关于php - Mysql数据库警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31894123/

相关文章:

mysql - SELECT AND INSERT QUERY into multiple table with conditions

php - 具有不同帐户的两个不同用户在 Twitter 上关注同一个人,并且数据库将相同的提要存储两次。如何避免?

php - MySQL - 从3个表中获取数据

sql - 为数据库中的单个字段存储多个值

Laravel session 中的数据库连接

mysql - 如何排除某些表被记录在 mysql 中?

php - 无法使用 Carbon formatLocalized 方法返回本地化的 AM/PM 时间格式?

php - 使用 fgetcsv() 在 PHP CSV 上传中转义撇号时出现问题

带有 MySQL 的 PHP 仅对表的第一行返回正确的结果

php - 如何从已经运行的实例中执行 matlab 代码?