2016-10-07 7 views
0

いくつかのコードに問題がありますPHP + Modal + FORM + MYSQL

私はモーダルでPHPフォームを持っています。

PHPコード:

<?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>'; 
} 
} 

?> 

、同じファイル内に、私はモーダル持っている:

<!-- 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> 

と動作しないことを...なぜ? 私はAJAXで試してみて、何も働かない... ありがとう!

+0

「うまくいきません」どういうふうに動作するのか、あるいは説明してくれると思いますか? –

+0

これは設定されていないため、これを設定していなかったためです。(isset($ _ POST ['submit'])){' – devpro

答えて

0

ここtype="submit2"が何であるかを知ってはいけない:

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

あなたのようなチェックされているので、あなたは、単に<input type="submit">フィールド

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

を使用することができます。

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

その他の提案:

ストップあなたはまだあなたがif(count($_POST) > 0)

のように確認することができるよりも<button>タグを使用する場合は、その非推奨となり、PHP 7で閉じ、あなたは、mysqli_またはPDO

を使用したりすることができますmysql_*を使用してHow can I prevent SQL injection in PHP?のコードはSQLインジェクション用にオープンされているため、このコードを使用する必要があります。

+0

もう一つの提案から、mysqliやPDOを使う方が良いでしょうか? –

+0

@ONLINETELEKOM PDO prepared statement – devpro

0

あなたが設定したactionのために動作しません。

action="index.php?stranica=katalog"action="$_SERVER["PHP_SELF"]"postに変更してください。

希望すると、これが役立ちます。