0

I've been having trouble with this one piece of code, and can't seem to sort out the problem.

I've looked online and the error im currently getting has something to do with a failed query but as i follow the steps to solve this problem it doesent seem to work.

What I need to do is have two separate columns one for the id, and the other for the data which the ids hold and I need it to pull information from my table called tbl typeofbusiness

This is my code :

  <tr>
    <td>Type of Business:</td>
    <td>
      <select name="typeofbusiness">
        <option value=''> - select type of business -</option>
        <?php 
        $sql = "SELECT tbl_typesofbusiness.ID, tbl_typesofbusiness.Agent
        FROM tbl_typesofbusiness";
        $res = mysqli_query($con,$sql)or ("Error: ".mysqli_error($con));
        while (list($id, $tob) = mysqli_fetch_row($res)); {
          echo "<option value='$id'>$tob</option>\n";
        }
        ?>
      </select>
    </td>
    <td>
      <span class="error">*
      <?php if (isset($errors['typeofbusiness'])) 
                echo $errors['typeofbusiness']; ?>
        </span>
      </td>
  </tr>

This creates the dropdown box and has a default value : select type of business, but it does not seem to pull the data from the database, as there are no other options under that. It also shows an error message.

Which I no how to solve by changing or to or die but when i make that change all code under or die dosent appear and i have another 6-7 fields which really isn't convenient and even worse when I do this no error message appears.

I need someone to help me with removing these problems so that it pulls information from the database and all the other errors no longer appear.

The error is:

Warning: mysqli_fetch_row() expects parameter 1 to be mysqli_result, boolean given in C:\wamp\www\AddLeads\addeadstemplate.php on line 256 Call Stack # Time Memory Function Location 1 0.2188 192992 {main}( ) ..\addeadstemplate.php:0 2 2.1875 205216 mysqli_fetch_row ( ) ..\addeadstemplate.php:256

Pranav 웃
  • 8,469
  • 6
  • 38
  • 48
  • possible duplicate of [mysql\_fetch\_array() expects parameter 1 to be resource, boolean given in select](http://stackoverflow.com/questions/2973202/mysql-fetch-array-expects-parameter-1-to-be-resource-boolean-given-in-select) – CBroe Dec 03 '13 at 12:33
  • Since you love comments, i'll add `SO` provides you with spelling corrections, so how did `collumn` get through three times I wonder – gwillie Dec 03 '13 at 12:49

1 Answers1

0

While Loop close before the $error variable.

And Fetch array function not used for $error

<?php 
   $errors= mysql_fetch_array($res);
   ?>
   <td><span class="error">* <?php if (isset($errors['typeofbusiness'])) { echo$errors['typeofbusiness']; }?></span></td>

   </tr>

Try this.

Madurai
  • 297
  • 3
  • 16
  • still got the same error but now i got 3 more ( ! ) Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\wamp\www\AddLeads\addeadstemplate.php on line 263 Call Stack # Time Memory Function Location 1 0.0000 193368 {main}( ) ..\addeadstemplate.php:0 2 0.0625 205832 mysql_fetch_array ( ) ..\addeadstemplate.php:263 – user3061280 Dec 03 '13 at 12:36
  • ( ! ) Notice: Undefined index: agent in C:\wamp\www\AddLeads\addeadstemplate.php on line 402 Call Stack # Time Memory Function Location 1 0.0000 193368 {main}( ) ..\addeadstemplate.php:0 ( ! ) Notice: Undefined index: id in C:\wamp\www\AddLeads\addeadstemplate.php on line 402 Call Stack # Time Memory Function Location 1 0.0000 193368 {main}( ) ..\addeadstemplate.php:0 – user3061280 Dec 03 '13 at 12:37