-1

The logical error is when I will update the field from the database it displays an error like this:

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\maritime_database\subject_entry.php on line 79
Subjects Entry

The reason maybe because the subject code starts with a letter. It works fine when the subject code starts with a number but I want it also to work with a letter.

here's my code:

<?php
 if($opr=="upd")
    {
      $sql_upd=mysql_query("SELECT * FROM subjects WHERE sub_code=$id");
      $rs_upd=mysql_fetch_array($sql_upd); // it displays an error  
?>  

div id="style_informations">
    <form method="post">
        <div>
            <table border="0" cellpadding="5" cellspacing="0">


            <tr>
                <td>Subject Code</td>
                <td>
                    <input type="text" name="sub_code_txt" id="textbox" value="<?php echo $rs_upd['sub_code'];?>"  />
                </td>
            </tr>

            <tr>
                <td>Semester</td>
                <td>
                    <input type="text" name="semestertxt" id="textbox" value="<?php echo $rs_upd['semester'];?>"  />
                </td>
            </tr>

            <tr>
                <td>Subjects's name</td>
                <td>
                    <input type="text" name="subtxt"  id="textbox" value="<?php echo $rs_upd['subject_name'];?>" />
                </td>
            </tr>


            <tr>
                <td>Units</td>
                <td>
                    <input type="text" name="subtxt"  id="textbox" value="<?php echo $rs_upd['units'];?>" />
                </td>
            </tr>


            <tr>
                <td>Note</td>
                <td>
                    <textarea name="notetxt" cols="23" rows="3"><?php echo $rs_upd['note'];?></textarea>
                </td>
            </tr>

            <tr>
                <td colspan="2">
                    <input type="reset" value="Cancel" id="button-in"/>
                    <input type="submit" name="btn_upd" value="Update" id="button-in"  />
                </td>
            </tr>
        </table>

        </div>
    </form>
user3808774
  • 57
  • 1
  • 5

3 Answers3

0

Try this : $sql_upd=mysql_query("SELECT * FROM subjects WHERE sub_code='$id'");

Since subject code have letters, it must be considered as string. So quotes must be used.

arunrc
  • 628
  • 2
  • 14
  • 26
0

use mysqli_query($con,$query); where $con is the your connection statement which must be included in your php script and $query is your sql query which will fetch you your result set from database.

oreopot
  • 3,392
  • 2
  • 19
  • 28
0

mysql_fetch_array() expects parameter 1 to be resource, boolean given, It means the query returns the error.

Check the $id is exists or not. If it exists and it's type is string then apply ' (single quote) to the $id in query.

Santosh Jagtap
  • 995
  • 8
  • 17