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>