-1

这是我在所有字段中填写的错误,但它仍然会弹出并显示如下警告警告:mysql_fetch_assoc() 期望参数 1 是资源,在 C:\xampp\htdocs\Site\index.php 中给出的字符串第 35 行 请填写所有字段

代码:

<?php include ("inc/incfiles/header.inc.php"); 
?>
<?php
$reg = @$_POST['reg']; 
//decalring variables to prevent errors 
$fn = $ln = $un = $em = $em2 = $pswd = $pswd2 = $d = $u_check = ""; 
/** 
 * Alla dessa variablar nedan bör kunna bytas ut mot det ovan för att göra det lite enklare. 
 * */ 
/*$fn = ""; //First Name 
$ln = ""; //Last Name 
$un = ""; //Username 
$em = ""; //Email 
$em2 = ""; //Email2 
$pswd = ""; //Password 
$pswd2 = ""; // Password2 
$d = ""; // Sign Up Date 
$u_check = ""; // Check if username exists */ 
//registration form 
$fn = mysql_real_escape_string(@$_POST['fname']); 
$ln = mysql_real_escape_string(@$_POST['lname']); 
$un = mysql_real_escape_string(@$_POST['username']); 
$em = mysql_real_escape_string(@$_POST['email']); 
$em2 = mysql_real_escape_string(@$_POST['email2']); 
$pswd = mysql_real_escape_string(@$_POST['password']); 
$pswd2 = mysql_real_escape_string(@$_POST['password2']); 
$d = date("Y-m-d"); //Year - Month - Day 

if ($reg) 
{ 
    if ($em == $em2) 
    { 
        //Check if user alredy exists 
        $un_check = mysql_query("SELECT Count(*) AS count FROM users WHERE username='$un'");  
        $data=mysql_fetch_assoc("$un_check"); 
        if($data['count'] > 0){ 
            // Username Alredy In Use
            }
            else{
                // Username Free
            }
        { 
            //check all of the fields have been filed in 
            if ($fn && $ln && $un && $em && $em2 && $pswd && $pswd2) 
            { 
                // check that passwords match 
                if ($pswd == $pswd2) 
                { 
                    // cheack the maximum lenght of of username/first name/last name does not exceed 25 characters 
                    if (strlen($un) > 25 || strlen($fn) > 25 || strlen($ln) > 25) 
                    { 
                        echo "The maximum limit for username/first name/last name is 25 characters!"; 
                    } else 
                    { 
                        // check the maximum lenght of password deoes not exceed 25 characters and is not less that 5 
                        if (strlen($pswd) > 30 || strlen($pswd) < 5) 
                        { 
                            echo "Your password must be between 5 and 30 characters long!"; 
                        } else 
                        { 
                            //encrypt password and password 2 using md5 berfore sending to database 
                            $pswd = md5($pswd); 
                            $pswd2 = md5($pswd2); 
                            $query = mysql_query("INSERT INTO users VALUES ('','$un','$fn','$ln','$em','$pswd','$d','0')"); 
                            die("<h2>Welcome to Mysite</h2>Login to your account to get started ..."); 
                        } 
                    } 
                } else 
                { 
                    echo "Your passwords don't match!"; 
                } 
            } else 
            { 
                echo "Please fill in all fields"; 
            } 
        } 
    } 
} 
?>
<?
//Login Script
if (isset($_POST["user_login"]) && isset($_POST["password_login"])) {
    $user_login = preg_replace('#[^A-Za-z0-9]#i', '', $_POST["user_login"]); // Filter everything but numbers and letters
    $password_login = preg_replace('#[^A-Za-z0-9]#i', '', $_POST["password_login"]); //Filter everything but numbers and letters
    $sql = mysql_query ("SELECT id FROM users WHERE username='$user_login' AND password='$password_login' LIMIT 1"); // query the person
    //Cheack for their existance
    $userCount = mysql_num_rows($sql); //Count the number of rows returned
    if ($userCount == 1) }
        while($row = mysql_fetch_array($sql)){
            $id = $row["id"];
    }
         $_SESSION["id"] = $id;
         $_SESSION["user_login"] = $user_login;
         $_SESSION["password_login"] = $password_login;
         header("location: index.php");
         exit();
        } else {
        echo 'That information is incorrect try again';
        exit();
    }
}
?>
<?
//Login Script
if (isset($_POST["user_login"]) && isset($_POST["password_login"])) {
    $user_login = preg_replace('#[^A-Za-z0-9]#i', '', $_POST["user_login"]); // Filter everything but numbers and letters
    $password_login = preg_replace('#[^A-Za-z0-9]#i', '', $_POST["password_login"]); //Filter everything but numbers and letters
    $sql = mysql_query ("SELECT id FROM users WHERE username='$user_login' AND password='$password_login' LIMIT 1"); // query the person
    //Cheack for their existance
    $userCount = mysql_num_rows($sql); //Count the number of rows returned
    if ($userCount == 1) }
        while($row = mysql_fetch_array($sql)){
            $id = $row["id"];
    }
         $_SESSION["id"] = $id;
         $_SESSION["user_login"] = $user_login;
         $_SESSION["password_login"] = $password_login;
         header("location: index.php");
         exit();
        } else {
        echo 'That information is incorrect try again';
        exit();
    }
}
?>

<table class="homepageTable">
      <tr>
         <td width="60%" valign="top">
          <h2>Already a Member Loign Below!</h2></br>
          <form action="index.php" method="post" name="form1" id="form1">
             <input type="text" size="25" name="user_login" id="user_login" placeholder="Username" />
             <input type="password" size="25" name="user_password" id="user_password" placeholder="Password" /><br />
             <input type="submit" name="button" id="button" value="Login!">
          <form>
         </td>
         <td width="40%" valign="top"> 
          <h2>Sign Up Below</h2>
          <form action="#" method="post">
          <input type="text" size="25" name="firstname" placeholder="First Name" value="<?php echo $fn; ?>">
          <input type="text" size="25" name="lastname" placeholder="Last Name" value="<?php echo $ln; ?>">
          <input type="text" size="25" name="username" placeholder="Username" value="<?php echo $un; ?>">
          <input type="text" size="25" name="email" placeholder="Email" value="<?php echo $em; ?>">
          <input type="text" size="25" name="email2" placeholder="Repeat Email" value="<?php echo $em2; ?>">
          <input type="password" size="32" name="password" placeholder="Password">
          <input type="password" size="32" name="password2" placeholder="Repeat Password"><br />
          <input type="submit" name="reg" value="Sign Up!">
          </form>
         </td>
     </tr>
<table>
</body>
</html>
4

3 回答 3

2

您已将变量作为字符串放入,只需更改

$data=mysql_fetch_assoc("$un_check"); 

$data=mysql_fetch_assoc($un_check); 

它会起作用的;)

于 2013-05-02T17:19:31.330 回答
0

尝试

改变

$data=mysql_fetch_assoc("$un_check");

$data=mysql_fetch_assoc($un_check); 
于 2013-05-02T17:20:48.597 回答
0
<input type="text" size="25" name="**firstname**" placeholder="First Name" value="<?php echo $fn; ?>">
<input type="text" size="25" name="**lastname**" placeholder="Last Name" value="<?php echo $ln; ?>">

你需要正确定义变量:改变

<input type="text" size="25" name="**fname**" placeholder="First Name" value="<?php echo $fn; ?>">
<input type="text" size="25" name="**lname**" placeholder="Last Name" value="<?php echo $ln; ?>">

它会起作用。但仍然需要再看看(

**if ($reg) 
{ 
    if ($em == $em2) 
    {  ............. )
its not right ,and work right** 
于 2014-09-09T13:39:41.363 回答