0
$query = "SELECT `ip` FROM `banned` WHERE `ip` = '$ip'";
$retval = mysqli_query($conn, $query);
if(!$retval){
    die("Could not Execute Query: " . mysqli_error($conn));
} else {
    if(mysqli_num_rows($retval) == 0){
        echo "test";
    } else {
        header('Location: http://www.teutonic-development.net/index.php?p=banned');
    }
}  

when I'm running this code all that's printed out is: "Could not Execute Query:"

I really have absolutely no idea why it's doing this. I'm connecting fine in my init.php file. Which is where this file is.

My other script which just adds a log entry works fine. And if I run my $query in phpmyadmin's sql interpreter it runs perfectly fine (when I replace the $ip part with an actual ip of course)

Any suggestions?

1
  • It may help to include your connection code, there is nothing wrong with the query itself, so there must be some other reason that it is not executing. Commented Feb 19, 2015 at 17:52

1 Answer 1

1

Normally one would say that hey your query failed to execute story finish. But this case is interesting.

Your code is

die("Could not Execute Query: " . mysqli_error($conn));

and your error message is

Could not Execute Query:

Notice even though you have mysqli_error($conn) but there is no mysql error being shown. That confirms 100% that $conn is not properly established (contrary to what you think)

So take a look at your code again and see if $conn is really a mysqli resource and is available to your file in proper variable scope.

Sign up to request clarification or add additional context in comments.

4 Comments

$conn = mysqli_connect('localhost', 'BinKill', 'REMOVED PASS', 'tk_development'); If this were the case my other query would not execute successfully...
However as it turns out I'm an idiot. I closed the connection before I did the second query facepalm I've been working on this for a day. I need sleep
Do a var_dump($conn); right before you execute this query and you'll find out if it is available there or not.
See there you go :) Error messages really tell most of the story :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.