2015-08-08 167 views
1

所以我创建我的网页注册,并点击“提交”按钮后,我得到了这个错误...我创建了MySQL表,我不知道为什么这个错误显示... 错误: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"; 
    } 
    } 
} 
} 
?> 

Configdb文件:

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

thanx的帮助:)

+1

这并不能帮助你'或死亡( “数据库错误”)'这并不'或死亡(mysqli_error($ mysqli的))' –

+1

一旦你已经改变了代码按@弗雷德-II-。然后尝试将''localhost''改为''127.0.0.1'' – RiggsFolly

+0

好吧,所以我完成了你所说的,现在它显示了2个错误...... First-'Warning:mysqli_connect():(HY000/2003):Can '在第二行的/ home/u771616840/public_html/FreeDay/PHP Form 2/configdb.php''上连接到'127.0.0.1'(111“连接被拒绝”)的MySQL服务器上。第二:'Warning:mysqli_error()expect parameters 1是mysqli,布尔在/ home/u771616840/public_html/FreeDay/PHP Form 2/configdb.php在第2行给出' – FreeDay

回答

0

我想分享我解决这个问题... MySQL的是显示这个错误,因为我有错误的表型......在register.php是以下几点:

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

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

+0

你提到的错误只是简单地说,我无法连接..有这个问题的原因很多.. –