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条)

报告相同问题?

悬赏问题

  • ¥20 用HslCommunication 连接欧姆龙 plc有时会连接失败。报异常为“未知错误”
  • ¥15 网络设备配置与管理这个该怎么弄
  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?