3
$dc=fopen("numeu.txt","rb");
$row1=fgets($dc,120);   
$row2=fgets($dc,120);
$row3=fgets($dc,120);

fclose($dc);

$servername="localhost";
$username="root";
$password='';
$database="Stildev";

$conn = new mysqli($servername, $username, $password, $database);

$sql="SELECT poza1,poza2,poza3,poza4,poza5,poza6 FROM postari WHERE utilizator='".$row2."' AND subiect='".$row1."' AND id2='".$row3."'";


$resultat=$conn->query($sql);

echo $resultat->num_rows;

This piece of code returns 0 rows

There is no error and sql query works just fine in MySQL console.

Also i discovered that withought WHERE clause the code works.How you explain that?

15
  • 1
    subiect='".$row1."' subject spell is wrong whether its intentionally or it's a mistake ? Commented May 14, 2015 at 11:02
  • Have you tried to view the query using echo $sql? Commented May 14, 2015 at 11:04
  • yes i ve tried and i also paste it into the console after i saw it Commented May 14, 2015 at 11:08
  • Nagendra Nigade that is not a mistake ,it s romanian :)) Commented May 14, 2015 at 11:10
  • 2
    BTW since you wrap the $sql variable with double quotes (") you can just write ='$row2' instead of ='".$row2."' It may increase code readability (IMHO at least) Commented May 14, 2015 at 11:26

1 Answer 1

2

Is the password empty on purpose?

Try adding

if ($mysqli->connect_error) {
    die('Connect Error (' . $mysqli->connect_errno . ') '
        . $mysqli->connect_error);
}

Also, according to https://php.net/manual/ro/mysqli.query.php, this may help:

if ($result = $mysqli->query($sql)) {
    echo $result->num_rows;
    /* close result set */
    $result->close();
}

If you are using several result-returning queries, close previous results with ->close();

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

5 Comments

You should update your answer to use the OO style, as he is using that. That'd be $conn->connect_errno in that case.
this should be a comment also.
yes it is empty because i use wamp server and i never changed the pass
the default pass is ''
My last update does not fit properly in a comment. Please see updated answer

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.