SQL query returning false in PHP

后端 未结 2 1864
感情败类
感情败类 2021-01-27 03:50

I am trying to perform this query in PHP however it keeps returning false. I have tried the query in phpMyAdmin and it works fine so if anyone can spot what is wrong that would

相关标签:
2条回答
  • 2021-01-27 04:37

    Close first connection using mysqli_close($conn); after first query is finished then open a new connection with include 'connection.php'; before the second query. Credit to @Chay22

    0 讨论(0)
  • 2021-01-27 04:55

    If you are using parameterized queries, then you have to pass the value for the parameter when you execute the prepared query.

    You also have to execute the prepared query. The prepare just passes the query to the database for compilation and optimisation, it does not actually execute the query.

    Also if you get an error in these database access statement, there are functions/methods you should use to show the the actuall error message which are a lot more useful than outputting something you make up yourself like echo "Error creating SQL statement";

    Also the ; is not necessary.

    $stmt = $conn->prepare("SELECT * FROM artist WHERE artID != ?");
    if ( $stmt === false ){
        echo $conn->error;
        exit;
    }
    
    
    $stmt->bindParam('i', $some_variable)
    
    $result = $stmt->execute();
    
    if ( $result === false ) {
        echo $stmt->error;
        exit;
    }
    
    0 讨论(0)
提交回复
热议问题