2016-11-05 190 views
-2
/*My data is not inserted in the database */ 
    <?php 
    $con=mysqli_connect("localhost", "root", ''); 
    mysqli_select_db($con,"test"); 

    if(isset($_POST['Submit'])) 

    { 
    $num =$_POST['h']; 

    for($i=0;$i<=$num;$i++) 

    { 

      $date  = $_POST["name_$i"]; 
      $name = $_POST["address_$i"]; 
      $contactNum = $_POST["contactNum_$i"]; 
      $loan = $_POST["loan_$i"]; 
      $status= $_POST["status_$i"]; 
     /*data is not stored in db and it doesn't show any error*/ 

    mysqli_query($con,"INSERT INTO `com` Values('$date', '$name', '$contactNum','$loan','$status')"); 

    } 

    echo "<h1>Do`enter code here`ne!</h1>"; 
    } 
/*data is not inserted into db*/ 
    else 
    { 
     echo "not inserted"; 
    } 
    ? 

/*最初只有一行數據存儲到數據庫中,但實際上我在我的HTML代碼3行*/ /但現在連我的第一行數據也沒有插入/爲什麼我的價值觀不進入數據庫

+0

真的嗎?你讀過關於如何做INSERT'查詢的任何教程嗎? – junkfoodjunkie

+0

ofcourse我有 –

+0

然後你還沒有明白他們。再次閱讀並修改查詢。並添加錯誤處理,然後你會得到它爲什麼不起作用。 – junkfoodjunkie

回答

1

mysqli_query()一次只執行一個查詢。

如果你在用戶想要用戶的時候在數據庫中插入多行For Loop沒有。的記錄。

另一種方法是使用$ conn-> multi_query($ sql)方法。

對於示例訪問以下鏈接:enter link description here

+0

你甚至我給了循環 –

+0

PLZ幫我出 –

+0

[鏈接](http://www.w3schools.com/php/php_mysql_insert_multiple.asp) –

相關問題