Click here to Skip to main content
15,566,160 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Here is my code:

The error says it is on line 13. Line 13 is where this code is at:
if (mysqli_num_rows($stock_query)==0) {
.

<?php
    include("dbconnect.php");

    //if categoryID is not set, redirect back to index page
    if(!isset($_GET['tadilatID'])) {
      header("Location:index.php");
    }
// Select all hizmetveren items belonging to the selected categoryID
  $stock_sql="SELECT usta.ustaID, usta.namelastname, usta.email, usta.phonenumber, usta.website, tadilat.name AS tadname FROM usta JOIN tadilat ON usta.tadilatID=tadilat.tadilatID WHERE usta.tadilatID=".$_GET['tadilatID'];
  if($stock_query=mysqli_query($dbconnect,$stock_sql)) {
    $stock_rs=mysqli_fetch_assoc($stock_query);
    
  }
  ---->>>> Line 13: Error Line -> if (mysqli_num_rows($stock_query)==0) {
    echo "Pek Yakinda Hizmetinizde";
  } else {
    ?>

      <h1><?php echo $stock_rs['tadname']; ?></h1>
    <?php do {
      ?>
<style>
.item{
line-height: 0.2;
width: 300px;
}
</style>
<h3>

        <div class="item">
          <a href="index.php?page=item&ustaID=<?php echo $stock_rs['ustaID']; ?>"><p><?php echo $stock_rs['namelastname']; ?></p>
          <p>E-Mail:🌐<?php echo $stock_rs['email']; ?></p>
          <p>Telefon: 📞<?php echo $stock_rs['phonenumber']; ?></p>
          <p>Website: 🌐<?php echo $stock_rs['website']; ?></p></a>
        </div>
        <hr>
    <?php

    }while($stock_rs=mysqli_fetch_assoc($stock_query));
    ?>

<?php
  }
?>


What I have tried:

I tried changing line 13 to ==1 instead of ==0. Or tried to switch else code with if else code. For example if previously it was: if x, else y, I switched it to if y, else x. Didn't work.

I have no idea at this point. Please help! Thank you very much.
Posted
Updated 10-Apr-21 22:29pm
Comments
Richard Deeming 12-Apr-21 6:45am    
Your code is vulnerable to SQL Injection[^]. NEVER use string concatenation to build a SQL query. ALWAYS use a parameterized query.
PHP: SQL Injection - Manual[^]

1 solution

 
Share this answer
 
Comments
zebestd 11-Apr-21 3:45am    
I don't understand. Could you please elaborate?
Richard MacCutchan 11-Apr-21 4:05am    
Look at the documentation:
Return Values ¶For SELECT, SHOW, DESCRIBE, EXPLAIN and other statements returning resultset, mysql_query() returns a resource on success, or false on error.

So a return value of false is telling you that your SELECT clause produced an error.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900