2017-01-23 84 views
0
<?php 
require "connection.php"; 
error_reporting(E_ALL); 
ini_set('display_errors',1); 
$username = "jasmine"; 
?> 
<!DOCTYPE html> 
<html lang="en"> 
<head> 
    <meta charset="utf-8"> 
    <meta name="viewport" content="width=device-width, initial-scale=1"> 
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> 
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script> 
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> 
    <link href="//netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap.min.css" rel="stylesheet"> 
<link href = "http://fonts.googleapis.com/css?family=Roboto:400"> 
<link href="//maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet"> 
<style> 
.modal-dialog{ 
    width:100%; 
    overflow: scroll; 

} 

</style> 


</head> 
<body> 


    <h2>Modal Example</h2> 
    <!-- Trigger the modal with a button --> 
    <button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal">Open Modal</button> 

    <!-- Modal --> 
    <div class="modal fade" id="myModal" role="dialog"> 
    <div class="modal-dialog"> 

     <!-- Modal content--> 
     <div class="modal-content"> 
     <div class="modal-header"> 
      <button type="button" class="close" data-dismiss="modal">&times;</button> 
      <h4 class="modal-title">ADD</h4> 
     </div> 
     <div class="modal-body"> 
      <p> 


<form action="" method="post"> 
<table> 
<thead> 
    <?php 
    $query = mysqli_query($conn,"SHOW columns FROM `rsvp`"); 
    // Loop over all result rows 
    while($row = mysqli_fetch_array($query)) 
    { 
     echo '<th>'; 
     echo $row["Field"]; 
     echo '</th>'; 
    } 
?> 
</thead> 
<tbody> 
<?php 
    $query4="SELECT * from `rsvp` WHERE `Gathered By` = '$username'"; 

    $result4= mysqli_query($conn, $query4); 
    while($row4 = mysqli_fetch_assoc($result4)){ 
     echo '<tr>'; 
     foreach($row4 as $values3){ 
     echo '<td>'; 
     echo '<input type="text" name="' .$row['Field'] .'">'; 
     echo '</td>'; 
     } 
     ?> 
     <td> 
     <input type="submit" name="add" value="Add"> 
     </td> 
     <?php 
     echo '</tr>';} 
?> 
</tbody> 
</table> 
</form> 

<?php 
if(isset($_POST['add'])){ 

$result2= mysqli_query($conn,"SELECT * FROM users WHERE username = '$username'"); 
$row2 = mysqli_fetch_row($result2); 

$row["Field"] = $columns; 
mysqli_query($conn,'INSERT INTO table (text, category) VALUES '.implode(',', $columns)); 




//// WHAT DO I DO HERE? 

} 
?> 

      </p> 
     </div> 
     </div> 

    </div> 
    </div> 



</body> 
</html> 

我有这样的代码,它应该当我点击添加按钮,但我怎么想写的“插入”查询时,我不知道,我想它的字段名插入值,任何人都可以帮助我呢? 而我得到当我点击添加错误是:插入值是动态的

Notice: Undefined variable: columns 
Notice: Undefined variable: columns 
Warning: implode(): Invalid arguments passed 

没有东西补充。

+0

你的问题是不重视我们,你想要什么。你想在所有领域得到后添加新的按钮。 –

+0

不,我有一个添加按钮我希望当我单击添加按钮时,我在输入字段内写入的变量会被插入并保存在数据库中@KumarRakesh – jasy

回答

0

尝试使用此代码

<?php 
if(isset($_POST['add'])){ 
     // insert query after upload data 
} 
?> 


<table> 
<thead> 
    <?php 
    $query = mysqli_query($conn,"SHOW columns FROM `call`"); 
    // Loop over all result rows 
    while($row = mysqli_fetch_array($query)) 
    { 
     echo '<th>'; 
     echo $row["Field"]; 
     echo '</th>'; 
    } 
?> 
</thead> 
<tbody> 
<?php 
    $query4="SELECT * from `call` WHERE `Generated By` = '$username'"; 

    $result4= mysqli_query($conn, $query4); 
    while($row4 = mysqli_fetch_assoc($result4)){ 
     echo ' <form action="" method="post"><tr>'; 
     foreach($row4 as $values3){ 
     echo '<td>'; 
     echo '<input type="text" name="field_name">'; 
     echo '</td>'; 
     } 
     ?> 
     <td> 
     <input type="submit" name="add" value="Add"> 
     </td> 
     <?php 
     echo '</tr></form>'; 
?> 
</tbody> 
</table> 

一些重要的变化,请在做你的最终像FIELD_NAME取等

+0

我现在看到它了,我有另一种形式,在这里看到它: – jasy

+0

我不能在这里发布我张贴在我的问题 – jasy

+0

在这个当你点击添加按钮然后页面刷新与帖子在相同的网址和这里之前获取查询你必须先插入数据文件<?php if(isset( $ _ POST [ '添加'])){载数据后, //插入查询 } ?> –