dpfw3607 2015-12-26 11:26
浏览 40

使用带有mysql和php的textarea更新多行也是单行

I want to update three textarea values to the database with a single submit button. But It is not working for me. When I try to update a single textarea then the value is updated to the database correctly, But when I add other two textareas, again it is not working. Other two textareas getting blank values.I know it is a basic question. But this drives me insane. Would anybody please help me to achieve this?

Here is my database table which name is optional and it has some default values:

http://i.stack.imgur.com/afhXJ.png

Here is my three text areas which read the options table default values. When enter a new text it will then insert into the options table according to the option name.

http://i.stack.imgur.com/XUFrW.png

Here is my HTML code:

<form name="settings" role="form" method="post" action="bangla_insert_submit.php">

    <h5>Insert Bangla Head Here:</h5>
    <textarea name="bangla_head" style="width: 100%"></textarea>
    <h5>Insert Chamber Head Here:</h5>
    <textarea name="chamber_head" style="width: 100%"></textarea>
    <h5>Insert English Head Here:</h5>
    <textarea name="english_head" style="width: 100%"></textarea>
     <input name="submit" type="submit" class="btn btn-default" value="Submit" />
  </form>

Here is my submited file code.

if (isset($_POST['submit'])) {

    $bangla_head  = $_POST['bangla_head'];
    $chamber_head = $_POST['chamber_head'];
    $english_head = $_POST['english_head'];

    $result = mysql_query( "SELECT option_id, option_name, option_value FROM options" );

    while( $row = mysql_fetch_assoc($result)){

        if (isset($_POST['bangla_head']) && $row['option_name'] == 'bangla_head'){

            //If the option is now yes (isset checks returns true if the box is selected) and the option in the db is N then update.
            mysql_query( "UPDATE options SET option_value = '$bangla_head' WHERE  option_id ='20' ");
        }
        if (isset($_POST['chamber_head']) && $row['option_name'] == 'chamber_head'){

            //If the option is now yes (isset checks returns true if the box is selected) and the option in the db is N then update.
            mysql_query( "UPDATE options SET option_value = '$chamber_head' WHERE  option_id ='21' ");
        }
        if (isset($_POST['english_head']) && $row['option_name'] == 'english_head'){

            //If the option is now yes (isset checks returns true if the box is selected) and the option in the db is N then update.
            mysql_query( "UPDATE options SET option_value = '$english_head' WHERE  option_id ='22' ");
        }

    }
}
</div>
  • 写回答

2条回答 默认 最新

  • dongyao5186 2015-12-26 11:49
    关注

    Try this

     if (isset($_POST['bangla_head']) && ($_POST['bangla_head']!='') ) 
    

    isset() checks if a variable has a value including ( False , 0 , or empty string), but not NULL. Returns TRUE if variable exists otherwise returns FALSE.

    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题