php error but where is it? [closed]
OK Dreamweaver and my local host server keeping saying that their is a error but i have no idea where please help?
This is a php script to figure out if the user already has a account and then if he doesn't it registers him into the database
<html>
<head>
<style type="text/css">
p {color:white;font-size:20px;}
.toppa {width: 100%;background-color:#2D2D2D;}
</style>
<?php
//Database Information
$dbhost = "localhost";
$dbname = "a8423624_grubber";
$dbuser = "root";
$dbpass = "";
//Connect to database
mysql_connect ( $dbhost, $dbuser, $dbpass)or die("Could not connect: ".mysql_error());
mysql_select_db($dbname) or die(mysql_error());
$username = $_POST['username'];
$email = $_POST['email'];
$password = md5($_POST['password']);
$repassword = md5($_POST['repassword']);
$month = $_POST['month'];
$day = $_POST['day'];
$year = $_POST['year'];
$Intro = 1;
$admin = "no";
if (!(empty($username) or empty($email) or empty($password) or empty($repassword)))
{
//a Text field is empty
if ($password == $repassword) {
$checkuser = mysql_query("SELECT username FROM users WHERE username='$username'");
$checkuser1 = mysql_query("SELECT email FROM users WHERE email='$email'");
$email_exist = mysql_num_rows($checkuser1);
$username_exist = mysql_num_rows($checkuser);
// checks email
if ($username_exist > 0)
{
echo "<div class='toppa' align='center'>
<h1 align='Left'> Grubber </h1>
</div>
<p> You'r Name has been taken please try another Name. </P>";
include 'tryagain.html';
}
else
{
if ($email_exist > 0)
{
echo "<div class='toppa' align='center'>
<h1 align='Left'> Grubber </h1>
</div>
<p> You'r Email has been taken please try another Email.</P>";
include 'tryagain.html';
}
else
{
$themes = ("http://grubber.host56.com/Themes/Grubber.gif");
$date = ("$year/$month/$day");
$proimg = ("http://grubber.host56.com/images/defaultprof.png");
$query = "INSERT INTO users (admin,themes,proimg,Birthday,Intro,email, username, password)
VALUES('$admin','$themes','$proimg','$date', '$Intro', '$email', '$username', '$password')";
mysql_query($query) or die(mysql_error());
mysql_close();
echo 开发者_高级运维"<div class='toppa' align='center'>
<h1 align='Left'> Grubber </h1>
</div>
<p> Please sign in to test that your account works </P>";
include 'tryagain.html';
}
else
{
echo "<div class='toppa' align='center'>
<h1 align='Left'> Grubber </h1>
</div>
<p>You'r passwords are not the same please try again.</P>";
}
}
else
{
echo "<div class='toppa' align='center'>
<h1 align='Left'> Grubber </h1>
</div>
<p> Please fill in all fields </P>";
include 'tryagain.html';
}
}
}
?>
First, you should enable error_reporting
.
Secondly, you should sanitize your input using mysql_real_escape_string
(else harmful people could SQL inject) and thirdly you should use or die (mysql_error());
after your SQL queries, like this:
$checkuser = mysql_query("SELECT username FROM users WHERE username='$username'") or die(mysql_error());
$checkuser1 = mysql_query("SELECT email FROM users WHERE email='$email'") or die(mysql_error());
If your SQL query fails, you will see the proper error.
精彩评论