Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
PHP
elseif (isset($_POST['search'])) {

        # Save-button was clicked
        $vname = $_POST['vendorname'];

        // connect to mysql
        $link =  mysqli_connect("localhost", "root", "", "magna-billing");
        // mysql search query
        $query = "SELECT  `vendoraddress`, `vendorcontact`, 'vendorgst', 'vendorstateid', 'vendorcode' FROM `vendordetail` WHERE `vendorname` = $vname ";
        $result = mysqli_query($link, $query) ;
        if(mysqli_num_rows($result) > 0)
        {
        while ($row = mysqli_fetch_array($result))
        {

          $vadd = $row['vendoraddress'];
          $vcont = $row['vendorcontact'];
          $vgst = $row['vendorgst'];
          $vstate = $row['vendorstateid'];
          $vcode = $row['vendorcode'];

}

}

mysqli_free_result($result);
mysqli_close($link);

else {
  echo "Undefined";

}

}

 else {
  $vadd = "";
  $vcont = "";
  $vgst = "";
  $vstate = "";
  $vcode = "";
}




?>


What I have tried:

I am trying to show the database value in the text box after clicking on search button, Here I stuck somewhere. Getting Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result error. Thanks in advance.
Posted
Updated 27-Oct-17 10:21am
v2

It is explained in the documentation: PHP: mysqli::query - Manual[^].
 
Share this answer
 
With your posted code you have a syntax error in mysql query, as you posted it is

$query = "SELECT `vendoraddress`, `vendorcontact`, 'vendorgst', 'vendorstateid', 'vendorcode' FROM `vendordetail` WHERE `vendorname` = $vname ";

Here 'vendorgst' and 'vendorstateid' should be changed as `vendorgst` and 'vendorstateid'
 
Share this answer
 

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