duanlie4621 2015-02-13 17:19
浏览 42
已采纳

创建新闻模块:部分ADD

At the moment, Im trying to create "news module" on my website, starting with adding news to mysql database but its not working - after hitting button submit nothing happens - no new data in db.

    <?php
          $servername = "localhost";
          $username = "u296093122_admin";
          $password = ".";
          $dbname = "u296093122_datab";

        if(isset($add_n)){
            $conn = new mysqli($servername, $username, $password, $dbname);

          if ($conn->connect_error) {
           die("->Pripojenie neúspešné: " . $conn->connect_error);
                                    }

           $sql = "INSERT INTO Akcie(nadpis, obsah, timestamp)VALUES('$nadpis', '$obsah', NOW())";
           $result = $conn->query($sql);

        if(!$result){
            echo('Error ' . $mysql_error());
            exit();
        }else{
        mysql_close($conn);
        echo('Success!');
            }
    }else{
    ?>
    <form name="form1" method="post" action="<?php echo $PHP_SELF; ?>">
        <table width="50%" border="0" cellspacing="0" cellpadding="0">
            <tr>
                <td>Nadpis:</td>
                <td><input name="nadpis" type="text" id="nadpis"></td>
            </tr>
            <tr> 
                <td>Obsah novinky:</td>
                <td><textarea name="obsah" id="obsah"></textarea></td>
            </tr>
            <tr> 
                <td colspan="2"><div align="center">
                <input name="hiddenField" type="hidden" value="add_n">
                <input name="add" type="submit" id="add" value="Submit">
                </td>
            </tr>
        </table>
    </form>
<? } ?>
  • 写回答

1条回答 默认 最新

  • dongpu4141 2015-02-13 17:25
    关注

    You should use isset($_POST['hiddenField']) instead of isset($add_n). Best way use

    if (isset($_POST['hiddenField']) && $_POST['hiddenField'] == 'add_n')

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮