drxkx6149 2016-02-20 04:40
浏览 35

网站未正确检查数据库中的现有用户名或存储数据

I am a beginner who stumbled upon this social media website making video and started working on it. ( https://www.youtube.com/watch?v=EgqVNMTnmDQ&index=36&list=PLA7F9875BD031DC16 ) there seemed to be lots of errors and people commented solutions and I tried fixing myself going back and fourth and most things worked.

Now I'm mainly having trouble making the website to check for existing username on the server because even though there is nothing in the mysql database, it still displays 'username taken' when i fill in the form and submit it. and of course nothing is saved into the database.

It'd be greatly appreciated if you guys could help me

  • code used(copy and paste) to create table on phpmyadmin-

    CREATE TABLE IF NOT EXISTS users ( id int(11) NOT NULL AUTO_INCREMENT, username varchar(255) NOT NULL, first_name varchar(255) NOT NULL, last_name varchar(255) NOT NULL, email varchar(255) NOT NULL, password varchar(32) NOT NULL, sign_up_date date NOT NULL, activated enum('0', '1') NOT NULL, PRIMARY KEY (id) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

-main file-

<?php 
$servername = "localhost";
$username = "root";
$passsword = "";
$databasee = "dbdb";
$con = mysqli_connect($servername, $username, $passsword) or die("Couldn't connect to SQL server");
mysqli_select_db($con, $databasee) or die("Couldn't select DB");
?>


<!doctype html>
<html>
<head>
  <title>Findfriends</title>
  <link rel="stylesheet" type="text/css" href="./css/style.css">
</head>
<body>
  <div class="headerMenu">
  <div id="wrapper">
    <div class="logo">
      <img src="./img/logo.png"></div>
<div class="search_box">
<form action="search.php" method="GET" id="search">
<input type="text" name="q" size="60" placeholder="Search ..."/>
</form>
</div>
<div id="menu">
  <a href="#"/>home</a>
  <a href="#"/>about</a>
  <a href="#"/>sign up</a>
  <a href="#"/>sign in</a>
</div>
 </div>
  </div>
?>




<?php
error_reporting (E_ALL);
ini_set ('display_errors', 1);

$reg = @$_POST['reg'];
$fn = "";
$ln = "";
$un = "";
$em = "";
$em2 = "";
$pswd = "";
$pswd2 = "";
$d = "";
$u_check = "";

$fn = strip_tags(@$_POST['fname']);
$ln = strip_tags(@$_POST['lname']);
$un = strip_tags(@$_POST['username']);
$em = strip_tags(@$_POST['email']);
$em2 = strip_tags(@$_POST['email2']);
$pswd = strip_tags(@$_POST['password']);
$pswd2 = strip_tags(@$_POST['password2']);
$d = date("Y-m-d");


if ($reg) {
if ($fn&&$ln&&$un&&$em&&$em2&&$pswd&&$pswd2) {


  $u_check = mysqli_query($con, "SELECT username FROM users WHERE username = '$un' ");
   $check = mysqli_num_rows($u_check); 
if ($check = 0){ 


 if ($em==$em2) {


  if ($pswd==$pswd2) {


    if (strlen($un)>25||strlen($fn)>25||strlen($ln)>25) {
     echo "The maximum limit for username/first name/lastname in 25 characters!";
      }


     if (strlen($un)>25||strlen($fn)>25||strlen($ln)>25) {
     echo "The maximum limit for username/first name/lastname in 25 characters!";
      }       



    else {
     if (strlen($pswd)>30||strlen($pswd)<5) {
     echo "Your password must be betwenn 5 and 30 characters long"; }

    else {
     $pswd = md5($pswd);
     $pswd2 = md5($pswd2);
     $query = mysqli_query($con, "INSERT INTO users VALUES ('', '$un', '$fn', '$ln', '$em', '$pswd', '$d', '0')");
     die("<h2>Welcome to fiendFriends</h2> Login your account to get started...");
     }
     }


} 

} else {echo "email dont match";}
} else {echo "username taken";}
} else {echo "fill in all the fields";}
}

?>







   <div style="width: 800px; margin: 0px auto 0px auto;">
     <table>
      <tr>
       <td width="60%" valign="top">
        <h2>Sign Up Today!</h2>
       </td>

       <td width="40%" valign="top">
        <h2>Sign Up Below!</h2>
         <form action="#" method="POST">
                <input type="text" name="fname" size="25" placeholder="First Name" /> <br /><br />
                <input type="text" name="lname" size="25" placeholder="Last Name" /> <br /><br />
                <input type="text" name="username" size="25" placeholder="Username" /> <br /><br />
                <input type="text" name="email" size="25" placeholder="Email" /> <br /><br />
                <input type="text" name="email2" size="25" placeholder="Confirm Email" /><br /><br />
                <input type="text" name="password" size="25" placeholder="Password" /> <br /><br />
                <input type="text" name="password2" size="25" placeholder="Confirm Password" /> <br /><br />
                <input type="submit" name="reg" value="Sign Up!">
          </form>
       </td>
      </tr>
     </table>

</div>
</body>
</html>
  • 写回答

2条回答 默认 最新

  • douchu4048 2016-02-20 04:52
    关注

    if ($check = 0 ) is incorrect. You are assigning that way. You want to compare using ==

    Do this instead:

    if ($check == 0 )
    
    评论

报告相同问题?

悬赏问题

  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 Revit2020下载问题
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 单片机无法进入HAL_TIM_PWM_PulseFinishedCallback回调函数
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线