1

While I was coding my online store I got this strange error message that I never saw it before!

Fatal error: Can't use function return value in write context on line 5

Here's my code

    <?php 
                        if (isset($_GET['pro_id'])){
                            $product_id = $_GET['pro_id'];
                            $query = $con->query("SELECT * FROM viewcounter WHERE productcode='$product_id'"); 
                            if(mysqli_num_rows($query) = 0){
                                $insert_id = "insert into viewcounter (productcode) values ('$product_id')";
                                $insert_id = mysqli_query($con, $insert_id);
                                mysql_query("UPDATE viewcounter SET `views`=`views`+1 WHERE productcode='$product_id'")
                            }
                            $get_pro = "select * from products where product_id='$product_id'";
                            $run_pro = mysqli_query($con,$get_pro);
                            while($row_pro = mysqli_fetch_array($run_pro)){

                                $_SESSION['pro_id'] = $row_pro['product_id'];
                                $_SESSION['pro_cat'] = $row_pro['product_cat'];
                                $_SESSION['pro_brand'] = $row_pro['product_brand'];
                                $_SESSION['pro_title'] = $row_pro['product_title'];
                                $_SESSION['pro_price'] = $row_pro['product_price'];

                                echo '....';
";}}?>

And this is line 5 that I get the error message:

if(mysqli_num_rows($query) = 0){

Note: I skipped writing the code that connects my database here cause it's already alright!

1 Answer 1

2

if(mysqli_num_rows($query) = 0){

That is assigning the value of the function to 0

For comparison, you need double or triple:

if(mysqli_num_rows($query) == 0){

More info on PHP comparison operators

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

Comments

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.