我得到错误查询是空的..我不知道为什么我得到这个..代码似乎没问题请帮助我。
在执行时我收到错误。在选择查询之前显示查询为空..
当我尝试在 wamp 服务器上执行代码时,它还显示未定义索引的错误
这是代码
<?php
if(isset($_POST['username'])){
# connect to the database here
# search the database to see if the user name has been taken or not
include 'config.php';
//$username=$_POST['username'];
$query = "SELECT * FROM account WHERE userid='$username' ";
//$sql = mysql_query($query);
//$row = mysql_fetch_array($sql);
$sql=mysql_query($sql) or die($sql.">>".mysql_error());
$row=mysql_num_rows($sql);
//if($num>0){ //check if
#check too see what fields have been left empty, and if the passwords match
if($row>0|| empty($_POST['fname'])||empty($_POST['lastname'])|| empty($_POST['username'])||empty($_POST['password1'])|| empty($_POST['password2'])|| empty($_POST['day'])|| empty($_POST['Month'])|| empty($_POST['year'])|| empty($_POST['gender']) || empty($_POST['contact'])||$_POST['password1']!=$_POST['password2']){
# if a field is empty, or the passwords don't match make a message
$error = '<p>';
if(empty($_POST['fname'])){
$error .= 'First Name can\'t be empty<br>';
}
if(empty($_POST['lastname'])){
$error .= 'Last Name can\'t be empty<br>';
}
if(empty($_POST['username'])){
$error .= 'Email can\'t be empty<br>';
}
if(empty($_POST['password1'])){
$error .= 'Password can\'t be empty<br>';
}
if(empty($_POST['password2'])){
$error .= 'You must re-type your password<br>';
}
if(empty($_POST['day'])){
$error .= 'Day is not selected<br>';
}
if(empty($_POST['Month'])){
$error .= 'Month is not selected<br>';
}
if(empty($_POST['year '])){
$error .= 'Year is not selected<br>';
}
if(empty($_POST['gender'])){
$error .= 'Gender is not selected <br>';
}
if(empty($_POST['contact'])){
$error .= 'contact is not selected<br>';
}
if($_POST['password1']!=$_POST['password2']){
$error .= 'Passwords don\'t match<br>';
}
if($row>0){
$error .= 'User Name already exists<br>';
}
$error .= '</p>';
}else{
Code will be written later :)
}
}
# echo out each variable that was set from above,
# then destroy the variable.
if(isset($error)){
echo $error;
unset($error);
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Online Plateform to Search Missing People</title>
<link href="style.css" rel="stylesheet" type="text/css" media="screen" />
</head>
<body>
<div id="main">
<?php include('header.php'); ?>
<div id="content" class="container">
<div id="posts">
<div id="signup-form">
<!--BEGIN #subscribe-inner -->
<div id="signup-inner">
<h2>Please Register Here :)</h2>
<p>Please complete the fields below, ensuring you use a valid email address as you will be sent a validation code which you will need the first time you login to the site.</p>
<form id="send" name="form" method="post" action="">
<p>
<label for="name">Name *</label>
<input type="text" name="fname" <?php echo 'value="'.$_POST['fname'].'"'; ?> />
</p>
<p>
<label for="lastnamme">Father Name</label>
<input type="text" name="lastname" <?php echo 'value="'.$_POST['lastname'].'"'; ?> />
</p>
<p>
<label for="username">Email Address *</label>
<input type="text" name="username" <?php echo 'value="'.$_POST['username'].'"'; ?> />
</p>
<p>
<label for="password">Password *</label>
<input type="password" name="password1" <?php echo 'value="'.$_POST['password1'].'"'; ?> />
</p>
<p>
<label for="cpassword">Confirm Password *</label>
<input type="password" name="password2" <?php echo 'value="'.$_POST['password2'].'"'; ?> />
</p>
<p>
<label for="dob">Date of Birth *</label>
<select name="day" >
<option value="year">Day </option>
<?php for($i=0;$i<=31;$i++)
{
?>
<option value="<?php echo $i; ?>"><?php echo $i."<br>"; ?></option>
<?php } ?>
</select>
<select name="Month" >
<option value="Month" selected>Month</option>
<option value="January">January</option>
<option value="February">February</option>
<option value="March">March</option>
<option value="April">April</option>
<option value="May">May</option>
<option value="June">June</option>
<option value="July">July</option>
<option value="August">August</option>
<option value="September">September</option>
<option value="October">October</option>
<option value="November">November</option>
<option value="December">December</option>
<option value="unknown" >Unknown</option>
</select>
<select name="year" >
<option value="year">Year </option>
<?php for($i=1920;$i<=2013;$i++)
{
?>
<option value="<?php echo $i; ?>"><?php echo $i."<br>"; ?></option>
<?php } ?>
</select>
</p>
<p>
<label for="gender">Gender</label>
<select type="text" <?php echo 'value="'.$_POST['gender'].'"'; ?> name="gender" >
<option value="male">Male </option>
<option value="female">Female</option>
<option value="other">other</option>
</select>
</p>
<p>
<label for="contactno">Contact No</label>
<input id="contact" type="text" name="contact" <?php echo 'value="'.$_POST['contact'].'"'; ?> />
</p>
<p>
<input type="submit" id="submit" name="submit" value="Sign Up" />
</p>
</form>
<div id="required">
<p>* Required Fields<br/>
NOTE: You must activate your account after sign up</p>
</div>
</div>
<!--END #signup-inner -->
</div>
<!--END #signup-form -->
</div>
</div>
</div><!-- end content -->
</div><!-- end main -->
<?php include('footer.php'); ?>
</body>
</html>