Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/87.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/haskell/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用PHP和Jquery在模式文本框中显示值_Php_Jquery_Sql - Fatal编程技术网

使用PHP和Jquery在模式文本框中显示值

使用PHP和Jquery在模式文本框中显示值,php,jquery,sql,Php,Jquery,Sql,我正在尝试使用PHP和JQuery将SQL数据库中的值显示到文本框中。正在检索这些值,但不会显示在文本框中。我做错了什么 <?php require 'UpdateTimerSQL.php'; ?> <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title&g

我正在尝试使用PHP和JQuery将SQL数据库中的值显示到文本框中。正在检索这些值,但不会显示在文本框中。我做错了什么

<?php

require 'UpdateTimerSQL.php';

?>


<!DOCTYPE html>
<html>
 <head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>LiveData</title>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
  <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
 </head>
 <body>

<div class="container">
<h2>Ajax</h2>
<p>Update Timer</p>
<table class="table">
<?php
    $table = mysqli_query($connection, 'SELECT * FROM Timers');
    while($row = mysqli_fetch_array($table)){ 
      ?>
        <tr id="<?php echo $row['ID']; ?>">
            <th>Timer_1</th>
            <td data-target="Timer_1"><?php echo $row['Timer_1']; ?></td>
              <th> 
            <a href="#" data-role="update" class="btn btn-primary" data-id="<?php echo $row['ID']; ?>">Update</a> 
             </th> 
        </tr>
     <?php
          } 
     ?>
    </table>

    <div class="container">


  <div class="text-center"></div>

</div>

<!-- Modal -->
<div id="myModal" class="modal fade" 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">Modal Header</h4>
      </div>
      <div class="modal-body">
        <div class="form-group">
          <label>Neutral Timer 1</label>
          <input type="hidden" id="ids" class="form-control">
          <input type="text" id="Timer_1" class="form-control">

        </div>
        <div class="modal-footer">
          <a href="#" id="save" class="btn btn-primary pull-right">Update</a>
          <button type="button" class="btn btn-default pull-left" data-dismiss="modal">Close</button>
        </div>
      </div>
    </div>
  </div>


  <script>
$(document).ready(function(){

  $(document).on('click', 'a[data-role=update]', function() {
    var id = $(this).data('id');
    //this(a tag)->tr(id)->td(data attr)->text
    var Timer_1=  $(this).closest('tr[id=' + id + ']').find("td[data-target='Timer_1']").text();
    //putting value in input box
    $('#Timer_1').val(Timer_1);
    $('#myModal').modal('toggle');
  });


UpdateTimerSQL.php

<?php
  $connection = mysqli_connect(...........);

  if(isset($_POST['ID'])){
  $Timer_1= $_POST['Timer_1'];
  $ids = $_POST['ID'];

   $result = mysqli_query($connection,"UPDATE Timers SET
   Timer_1='$Timer_1' WHERE ID ='$ids'");
   if($result){
    echo 'data updated';
   }

   }
  ?>

您的表结构无效。此外,计时器\u 1无法找到所需的文本,这是它无法工作的原因

您的php代码应该如下所示:

 <table class="table">
<?php
    $table = mysqli_query($connection, 'SELECT * FROM Timers');
    while($row = mysqli_fetch_array($table)){ 
      ?>
        <tr id="<?php echo $row['ID']; ?>">
            <th>Timer 1</th>
            <td data-target="Timer_1">
                <?php echo $row['Timer_1']; ?>
            </td>
              <th> 
            <a href="#" data-role="update" class="btn btn-primary" data-id="<?php echo $row['ID']; ?>">Update</a> 
             </th> 
        </tr>
     <?php
          } 
     ?>
    </table>
AJAX 更新计时器

计时器1 某物 计时器1 什么 &时代; 模态头 计时器1 关
修复你的HTML布局,这可能会使事情正常工作。格式不正确的HTML通常会使更复杂的布局不可用work@RiggsFolly非常感谢。对不起。但标签下存在主要问题。我仍然不确定为什么该值没有显示。您好,非常感谢。我能够在示例中的文本字段中显示mySQL值。但当我尝试更新mySQL表时,它并没有得到更新。我做错了什么?我已在“编辑”下更新了有问题的代码。此$\u POST['ID']应为$\u POST['ID'],因为您已在ajax调用中将ID作为参数传递,而不是ID。谢谢,这是缺少的:
 <table class="table">
<?php
    $table = mysqli_query($connection, 'SELECT * FROM Timers');
    while($row = mysqli_fetch_array($table)){ 
      ?>
        <tr id="<?php echo $row['ID']; ?>">
            <th>Timer 1</th>
            <td data-target="Timer_1">
                <?php echo $row['Timer_1']; ?>
            </td>
              <th> 
            <a href="#" data-role="update" class="btn btn-primary" data-id="<?php echo $row['ID']; ?>">Update</a> 
             </th> 
        </tr>
     <?php
          } 
     ?>
    </table>