2012-02-26 20 views
0

MySQLに入力フィールドデータを挿入する必要があります。しかし、入力フィールドはさまざまです。 ループでPHPを複数挿入する

<form method="post" action=""> 
    <div class="add_word"><div class="word_label">Malayalam</div><input type="text" name="english" class="hinput" /></div> 
<div id="add_words"> 
    <div class="line"><div class="word_label">English</div><input name="malayalam[]" class="search_word input1 hinput" type="text" /></div> 

</div> 
    <div id="add_wordD">+ <a id="add">Add another word</a> 
     <input type="submit" name="submit" value="submit" class="submit" style="margin-left:30px;"/> 
    </div> 
    </form> 

は、あなたがそれのためのソリューションをしてくださいお願いできhttp://www.chatfitness.com/add_malayalam.php

enter image description here

jQueryの追加入力フィールドコード

$(document).ready(function() { 
    var scntDiv = $('#add_words'); 
    var wordscount = 1 ; 
    var i = $('.line').size() + 1; 
    $('#add').click(function() { 
     wordscount++; 
//  $('<div class="line">Word is ' + wordscount + '<input type="text" class="input' + wordscount + '" value="' + wordscount + '" /><a class="remScnt">Remove</a></div>').appendTo(scntDiv); 
     $('<div id="em_in" class="line" style="display:none"><div class="word_label">English </div><input type="text" name="malayalam[]" class="input' + wordscount + ' hinput" /><a class="remScnt">Remove</a></div>').appendTo(scntDiv).slideDown(); 
     i++; 
     return false; 
    }); 

フォームの詳細私のページを見てみましょう。あなたが別の行に各翻訳を挿入したい場合は、事前

+0

使用しているコードを投稿してください。 –

+0

私はあなたの質問を理解していない! – markus

+0

私たちはhtmlのコードを知っていると思われます!すばらしいです!申し訳ありませんが、私に教えられた本はありません。 – itachi

答えて

2

で おかげで、これは方法です:

もちろん
<?php 

$eng = mysql_real_escape_string($_POST['english']); 
foreach ($_POST['malayalam'] as $val) { 
    $mal[] = mysql_real_escape_string($val); 
    $query = sprintf("INSERT INTO table (english, mal) VALUES (%s, %s)", 
     $eng, 
     mysql_real_escape_string($mal); 
    // execute query 
} 

私が何をデータベースラッパーあなたが使用したり、どのようなテーブルレイアウトだか分かりません。