【问题标题】:How to change mysql column from html table with php scripting如何使用 php 脚本从 html 表中更改 mysql 列
【发布时间】:2014-12-09 12:20:45
【问题描述】:

您好编码人员

这是我的mysql表

这里是用户界面

编码是这样的

<?php
 // Connect to the database
$dbLink = new mysqli('127.0.0.1', 'root', '', 'hct_db');
if(mysqli_connect_errno()) {
    die("MySQL connection failed: ". mysqli_connect_error());
}

 // Query for a list of all existing files
$sql = 'SELECT `quote_id`, `name`, `mime`, `size`, `created`, `status` FROM `quote`';
$result = $dbLink->query($sql);

// Check if it was successfull
if($result) {
   // Make sure there are some files in there
    if($result->num_rows == 0) {
    echo '<p>There are no files in the database</p>';
}
else {?>

                        <div class="table-responsive">
                            <table class="table table-striped table-bordered table-hover" id="dataTables-example">
                                <thead>
                                    <tr>
                                        <th>Quote ID</th>
                                        <th>File Name</th>
                                       <th>File</th>
                                        <th>Size</th>
                                    <th>Created</th>
                                        <th></th>
                                        <th></th>
                                        <th></th>

                                    </tr>

                                </thead><tbody>
                               <?php
    while($row = $result->fetch_assoc()) {
    if ($row["status"]=="Not Approved")
    {
         echo "<tr>";
   echo "<td>" . $row['quote_id'] . "</td>";

  echo "<td>" . $row['name'] . "</td>";

     echo "<td>" . $row['mime'] . "</td>";
  echo "<td>" . $row['size'] . "</td>";
  echo "<td>" . $row['created'] . "</td>";
echo '<td><a href="get_file.php?quote_id=' . $row['quote_id'] .'">Download</a></td>';
echo "<td><input type='submit' name='submit' value='Approved'></td>";
echo "<td><input type='submit' name='submit' value='Reject'></td>";

echo "</tr>";
    }}
    ?>
</tbody>
</table>
</div>                               
                           </div>
                        <!-- /.table-responsive -->

<?php       
$result->free();
}
// Close the mysql connection
$dbLink->close();}
?>    

【问题讨论】:

  • 需要使用ajax调用更改数据库的php脚本。然后使用javascript将信息更新到客户端,无需刷新。
  • 谢谢@Mattigins,你能给我一些与此相关的链接吗?

标签: php mysql uitableview


【解决方案1】:

1) 你需要使用 ajax。
2) 对于每个按钮,您可以使用如下形式:

  <form method="post" action="approved.php" target="_self">
        <td>
            <input type='submit' name='submit' value='Approved'>
            <input type='hidden' name='quoteID' value='<?php echo $row['quote_id']?>'>
        </td>
   </form>

approved.php:

  mysqli_connect
  $approvedElement = $_POST['quoteID'];
  $query = 'UPDATE ... WHERE `Quote ID` = \''.$quoteID.'\' ';
  mysqli_query($query);

所以在 ajax 之前,我建议您学习有关 GET 和 POST 方法的基础知识。 在此示例中,您需要:

 • form, to redirect the user to another page (approved.php, rejected.php)
 • $_POST, in the second page to retrieve the ID of the approved element, and use it in the next step 
 • mysql_query, after you have correctly coded the query and successfully connected to the           DB 

【讨论】:

  • 我已经完成了你上面提到的更新但是如何在那里做ajax?
猜你喜欢
  • 2011-02-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-04-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-11-25
相关资源
最近更新 更多