栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

使用Ajax,PHP,MYSQL更新表单

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

使用Ajax,PHP,MYSQL更新表单

最终弄清楚了。谢谢大家的帮助。

<p id="alert"></p>    <form id="form" method="post" action="/ajax/update_company_info.php">    <!-- start id-form -->    <table border="0" cellpadding="0" cellspacing="0"  id="id-form">    <tr>        <th valign="top">Business Name:</th>        <td><input type="text" name="company_name"  /></td>        <td></td>    </tr>    <tr>        <th valign="top">Address 1:</th>        <td><input type="text" name="address_1"  /></td>        <td></td>    </tr>    <tr>        <th valign="top">Address 2:</th>        <td><input type="text" name="address_2"  /></td>        <td></td>    </tr><tr>    <th>&nbsp;</th>    <td valign="top"> <input id="where" type="hidden" name="customer_id" value="1" /> <input type="submit" value="Save" id="submit">    </td>    <td></td></tr></table><!-- end id-form  --></form>

update.js

$(document).ready(function() {$('form').submit(function(evt) {  evt.preventDefault();   $.each(this, function() { // VARIABLES: Input-specific var input = $(this); var value = input.val(); var column = input.attr('name'); // VARIABLES: Form-specific var form = input.parents('form'); //var method = form.attr('method'); //var action = form.attr('action'); // VARIABLES: Where to update in database var where_val = form.find('#where').val(); var where_col = form.find('#where').attr('name');  $.ajax({      url: "/ajax/update_company_info.php",      data: {  val: value,  col: column,  w_col: where_col,  w_val: where_val      },      type: "POST",      success: function(data) {      $('#alert').html("<p>Sent Successfully!</p>");  }  }); // end post  });// end each input value}); // end submit}); // end ready

update_customer_info.php

    <?phpinclude($_SERVER['document_ROOT'] . '/load.php');function clean($value){    return mysql_real_escape_string($value);}// FORM: Variables were postedif (count($_POST)){    // Prepare form variables for database    foreach($_POST as $column => $value)        ${$column} = clean($value);    // Perform MySQL UPDATE    $result = mysql_query("UPDATE customers SET ".$col."='".$val."'        WHERe ".$w_col."='".$w_val."'")        or die ('Error: Unable to update.');}?>


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/383981.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号