【问题标题】:Saving a row and posting to same page via php通过php保存一行并发布到同一页面
【发布时间】:2011-11-14 23:26:25
【问题描述】:

我被这个困住了..我也是新手,所以不太有希望。我有一个使用 php 和 mysql 填充的 html 表。每行有 4 列,其中一列是“更新”按钮,语法如下

print("<input type='submit' value='Update' name='update' class='submit_button'/>");

现在,class='submit_button' 是新的,因为我在使用 json 的相关问题中添加了一个建议,功能在这里

$( '.submit_button' ).click( function(){

        var value = {};

        $( this ).closest( '.submit_button' ).find( 'input, select' ).each(function(){  
            value[ $(this).attr('name') ] = $(this).val();
        });

        $.post( "test.php", 
            value,
            function(data){
                //success
                alert( data );
            }, 
            "json"
        );

    });

我期待看到警报说它已发布或其他内容......但什么都没有......现在我也尝试向该行添加一个表单......但这也不起作用。这是我的完整 html 表格

print("<table id='results'><tr><th>ID</th><th>Image</th><th>Name</th><th>Price</th><th>Price Label</th><th>Description</th><th>Update</th></tr>");

     while($row2 = mysql_fetch_array( $result2 )){ 
         $client_id = $row2["client_id"];
         $client_name = $row2["client_name"];
         $client_disc = $row2["client_disc"];
         $client_price = $row2["client_price"];
         $client_image = $row2["client_image"];
         $client_price_label = $row2["client_price_label"];

         print("<tr>");   
         print("<td>");
         print("<p style='font-size:14px; color:blue; padding:0;'>$client_id</p>");
         print("</td>");          
         print("<td>");
         print("<img class='custom_rate' alt='' src='$client_image' />");
         print("</td>");
         print("<td width='100px'>");
         print("<input type='text' value='$client_name' name='clientname'/>");
         print("</td>");
         print("<td>");
         print("<input type='text' value='$client_price' name='clientprice'/>");
         print("</td>");
         print("<td width='100px'>");
         print("<input type='text' value='$client_price_label' name='clientpricelabel'/>");
         print("</td>");
         print("<td width='100px'>");
         print("<textarea cols='15' rows='2' name='description'>$client_desc</textarea>");
         print("</td>");
         print("<td width='100px'>");
         print("<input type='submit' value='Update' name='update'/>");
         print("</td>");
         print("</tr>");
    }

    print("</table>");

所以我不知道如何使这项工作,如果你能帮我详细说明 json 方式.. 或者如果有另一种方式......我在想也许更简单.. 我怎么能点击更新按钮并获取值并将它们存储在我可以使用它们的同一页面中的某个位置,然后我会将这些值传递给 php 变量并进行更新?

感谢您的耐心等待

【问题讨论】:

  • 你为什么使用所有这些打印语句而不是 .. ?> 语法?你知道,这样做太慢了;)。老实说,你的代码让我遇到了十几个问题。
  • 我可以回答其中之一 :) 我是 PHP 新手和所有的东西哈哈

标签: php javascript mysql html json


【解决方案1】:

这是一个提交按钮,因此它会在 Javascript 有机会运行之前提交您的页面。

尝试常规的 type="button" 看看是否可行。

【讨论】:

    【解决方案2】:

    也可以在关闭函数之前尝试return false;

    【讨论】:

      猜你喜欢
      • 2011-05-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-05
      • 1970-01-01
      • 1970-01-01
      • 2012-11-08
      相关资源
      最近更新 更多