douyou8266 2015-09-22 06:42
浏览 7

当主题代码是php中的字母时,如何显示字段? [重复]

This question already has an answer here:

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>
</div>
  • 写回答

3条回答 默认 最新

  • dongrong9938 2015-09-22 06:46
    关注

    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.

    评论

报告相同问题?

悬赏问题

  • ¥15 关于大棚监测的pcb板设计
  • ¥20 sim800c模块 at指令及平台
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计