douzhanshen0657 2016-10-07 15:02
浏览 50
已采纳

PHP +模态+ FORM + MYSQL [关闭]

I have a problem trying to work on some code

I have PHP form in MODAL.

PHP CODE:

<?php
// krerianje kataloga
if (isset($_POST['submit'])) {
$naslov = $_POST['naslov'];
$status = $_POST['status'];

if ($naslov != '' && $status != ''){
    $sql2= "INSERT INTO katalog(naslov,status) VALUES ('$naslov','$status')";
    $result2 = mysql_query($sql2,$baza);
    $poruka = '<center><hr style="color:green;width:98%"><h3 style="font-size:17px">Vaš katalog je kreiran.<center/></h3><hr style="color:green;width:98%"></center><br>';
}else {
    $poruka = '<center><hr style="color:green;width:98%"><h3 style="font-size:17px">Molimo Vas ispunite sva polja.<center/></h3><hr style="color:green;width:98%"></center><br>';
}
}

?>

And in SAME file I have modal:

<!-- Modal Structure -->
<div id="krerianjekataloga" class="modal">
    <div class="modal-content">

        <h4>Kreiranje Kataloga</h4>
        <form method="POST" name="katalog" action="index.php?stranica=katalog">
            <div class="input-field col s12">
                <label for="email" class="">Naslov Kataloga</label>
                <input id="naslov" name="naslov" class="required validate" aria-required="true" type="text">
            </div>
            <div class="input-field col s12">
                                        <div class="select-wrapper"><span class="caret">▼</span><input class="select-dropdown" readonly="true" data-activates="select-options-cde9ce7d-c5d2-8deb-ad2c-e8a5668916c4" value="Choose your option" style="" type="text"><ul id="select-options-cde9ce7d-c5d2-8deb-ad2c-e8a5668916c4" class="dropdown-content select-dropdown" style="width: 458px; position: absolute; top: 0px; left: 0px; opacity: 1; display: none;">
                                        <li class=""><span>Aktivno</span></li>
                                        <li class=""><span>Neaktivno</span></li></ul>
                                        <select id="status" name="status" class="initialized">
                                            <option value="1">Akivno</option>
                                            <option value="0">Neaktivno</option>
                                        </select></div>
                                        <label>Odaberite status kataloga</label>
                                    </div>

    </div>
    <div class="modal-footer">
       <button type="submit" style="float:right;" class="waves-effect waves-light btn m-b-xs"><i class="material-icons left">input</i>Spremi</button>
    </div>
    </form>
</div>

And that not work... why? I try with ajax and nothing work... Thanks!

  • 写回答

2条回答 默认 最新

  • douhui9380 2016-10-07 15:12
    关注

    Don't know what is type="submit2" here:

    <button type="submit2" style="float:right;" class="waves-effect waves-light btn m-b-xs">
    <i class="material-icons left">input</i>Spremi</button>
    

    You can simply use <input type="submit"> field

    <input type="submit" name="submit" value="Submit">
    

    Because you are checking like:

    if (isset($_POST['submit'])) { // here must need a field with name submit
    

    Other Suggestions:

    Stop using mysql_* its deprecated and closed in PHP 7, you can use mysqli_ or PDO

    Or, if you still want to use <button> tag than you can check like if(count($_POST) > 0)

    You also need to take of How can I prevent SQL injection in PHP? because you code is open for SQL Injection.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥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时遇到的编译问题