this is my connect file which is error free but seems to not connect to my database.
<?php
$username="root";$password="Abubba21";$database="posts";
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
mysql_close();
?>
Here is my code, I even have to put the php header at the bottom of the file because otherwise nothing will be displayed
<body>
<?php
$db_host = "localhost";
$db_username = "root"
$db_pass = "Abubba21";
$db_name = "accounts";
try
{
$db = new PDO('mysql:host='.$db_host.';dbname'.$db_name,$db_username,$db_pass);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
//$result = $db->query
}
catch(PDOException $e)
{
echo "Server error: ",$e->getCode()."invalid server";
}
$reg = @$_POST['reg'];
$un = "";
$pswd = "";
$em = "";
$em2 = "";
$pswd2 = "";
$un = strip_tags(@$_POST['username']);
$pswd = strip_tags(@$_POST['password']);
$em = strip_tags(@$_POST['email']);
$pswd2 = strip_tags(@$_POST['password2']);
$em2 = strip_tags(@$_POST['email2']);
if($reg){
if($em == $em2){
$u_check = mysql_query("SELECT username FROM accounts WHERE username = '$un'");
$check = mysql_num_rows($u_check);
if($check==0){
if($un&&$pswd&&$em&&$pswd2&&$em2){
if($pswd == $pswd2){
if(strlen($un)>25)
{
echo "The maximum limit for the username is 25 characters.";
}
else
{
if(strlen($pswd)>30||strlen($pswd)<5){
echo "Your password has to be between 5 and 30 characters.";
}
else
{
$pswd = md5($pswd);
$pswd2 = md5($pswd2);
$query = mysql_query("INSERT INTO accounts VALUES ('','un','pswd','em')");
die("<h2>Welcome</h2> Log in to start");
}
}
}
else
{
echo "Your passwords don't match";
}
}
else
{
echo "You must fill in all fields";
}
}
else
{
echo "Username is already token";
}
}
else
{
echo "Your emails don't match";
}
}
?>
<div class="body">
<div class="register">
<h1 class="heads">Register</h1><br><br><br><br>
<form action="#" method="post">
<div class="login">
<input type="text" name="username" value="" placeholder="Username ...">
<p />
<input type="password" name="password" value="" placeholder="Password ...">
<p />
<input type="password" name="password2" value="" placeholder="Password ...">
<p />
<input type="email" name="email" value="" placeholder="someone@somesite.com">
<p />
<input type="email" name="email2" value="" placeholder="someone@somesite.com">
<p />
<input type="submit" name="createaccount" value="Create Account">
</div>
</form>
</div class="register">
<div class="grad"></div>
<div class="header">
<div><span>Welcome</span></div> <br><br>
</div>
<br>
<form action="home.php" method="post">
<div class="login">
<input type="text" name="username" value="" size="30" placeholder="username"><br>
<input type="password" name="password" value="" size="30" placeholder="password">
<input type="submit" name="login" value="Login"><br>
</div>
</form>
</div>
<?php include("connect.php"); ?>