mysql data existence code not working

This question already has an answer here:

  • When to use single quotes, double quotes, and back ticks in MySQL 11 answers

  • First of all, make sure your database connection is correctly set up. The error you're getting clearly says that your $conn variable isn't a valid resource.

    Also, use prepared statements and parameterized queries . Do not use PHP variables within your query string, it's not secure at all. Use instead PDO or MySQLi

  • Using PDO:

    $stmt = $pdo->prepare('SELECT easy123 FROM users WHERE email = :email');
    
    $stmt->execute(array('email' => $email));
    
    foreach ($stmt as $row) {
        // do something with $row
    }
    
  • Using MySQLi:

    $stmt = $dbConnection->prepare('SELECT easy123 FROM users WHERE email = ?');
    $stmt->bind_param('s', $email);
    
    $stmt->execute();
    
    $result = $stmt->get_result();
    while ($row = $result->fetch_assoc()) {
        // do something with $row
    }
    

  • Your $query seems to be wrong. Try this:

    $query = mysql_query("SELECT easy123 FROM users WHERE email='$email'", $conn);
    

    Make sure $conn is properly defined aswell.

    链接地址: http://www.djcxy.com/p/69592.html

    上一篇: PHP

    下一篇: mysql数据存在代码无法正常工作