dqzuo0327 2013-05-08 17:10
浏览 12
已采纳

<tr onclick =“”>更新数据库ajax

i have a select customer page and when you click on a table row it should set the customer id of the order that is currently being built.

here is what i have already but it doesnt pick up the id of the customer it sets customer to 0 instead

function selectcust(str)

{
if (str=="")
  {
  document.getElementByid("description").innerHTML="";
  return;
  } 
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("description").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","php/insertcust.php?order=<?php echo $order; ?>&id="+str,true);
xmlhttp.send();
}

the php is

$id = $_GET['id'];
$order = $_GET['order'];

include('config.php');

$sqlins = "UPDATE `sales` SET customernumber='$id' WHERE invoice = '".$order."'";

if (!mysql_query($sqlins,$con))
  {
  die('Error: ' . mysql_error());
  }
 echo $id;

and the table row is

echo"
<tr value='" . $row[id] . "' onclick='selectcust(this.value)'><td>" . $row['surname'] . "</td><td>" . $row['firstname'] . "</td><td>" . $row['Postcode'] . "</td><td>" . $row['Houseno'] . "</td><td>" . $row['org'] . "</td><td>" . $row[id] . "</td></tr>"

;
  • 写回答

4条回答 默认 最新

  • duanquan4451 2013-05-08 17:12
    关注

    Table rows aren't supposed to have values or value attributes. Try a unique ID attribute:

    echo "<tr id='" . $row[id] . "' onclick='selectcust(this.id)'><td> <input type='text' src='images/btn_delete.png' value='" . $row[id] . "' onfocus='selectcust(this.value)' height='30'/>" . $row['surname'] . "</td><td>" . $row['firstname'] . "</td><td>" . $row['Postcode'] . "</td><td>" . $row['Houseno'] . "</td><td>" . $row['org'] . "</td><td>" . $row[id] . "</td></tr>";
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题