dongyoufo5672 2017-02-19 23:51
浏览 51

PHP表内联编辑 - Javascript函数

I am trying to create an inline edit function on my table, the user should be able to retype the values, and click the 'Save' button to update the database record.

I've hit a problem with the javascript function, its not reverting me to the next page as per 'window.location.href', which would be the php update qry page, that reverts me back to the original page to view the changes made.

The javascript function is meant to get the old id , and all of the possibly new td's within the record, which the user may have inline edited.

I had this working for the id itself, but with the addition of all the new values, ive messed up either on the js function or the action but (may the 'this'?) not exactly sure. I know mysql is rubbish and so on, im focusing on functionality at the time being.

JS FUNCTION

function edit_user(id,a,b,c,d,e,f,g,h,i,j,k) {

var tr = a.parentNode.parentNode;
var awb = String(tr.querySelector(".a").innerHTML);

var tb = b.parentNode.parentNode;
var del = String(tb.querySelector(".b").innerHTML);

var tc = c.parentNode.parentNode;
var vsl = String(tc.querySelector(".c").innerHTML);

var td = d.parentNode.parentNode;
var cli = String(td.querySelector(".d").innerHTML);

var te = e.parentNode.parentNode;
var pcs = String(te.querySelector(".e").innerHTML);

var tf = f.parentNode.parentNode;
var wgt = String(tf.querySelector(".f").innerHTML);

var tg = g.parentNode.parentNode;
var car = String(tg.querySelector(".g").innerHTML);

var th = h.parentNode.parentNode;
var snd = String(th.querySelector(".h").innerHTML);

var ti = i.parentNode.parentNode;
var stt = String(ti.querySelector(".i").innerHTML);

var tj = j.parentNode.parentNode;
var ard = String(tj.querySelector(".j").innerHTML);

var tk = k.parentNode.parentNode;
var ctm = String(tk.querySelector(".k").innerHTML);

// run query on server:
window.location.href = 'http://at-web2.comp.glam.ac.uk/students/14075377/14075377/php/edit-livedashboard-import.php?id='+id+'&newawb='+awbno+'&newvsl='+vsl+'&newcli='+cli+'&newpcs='+pcs+'&newwgt='+wgt+'&newcar='+car+'&newsnd='+snd+'&newstt='+stt+'&neward='+ard;;
return false;}

TABLE ACTION BUTTON

$awb = $get_info["AwbNo"];
echo "<a href='' onclick='return edit_user($awb,here,here,here,here,here,here,here,here,here);'>&nbspSave&nbsp</a>";

PHP UPDATE

include("../dbinfo.inc.php");
$comm=@mysql_connect(localhost,$username,$password);
$rs=@mysql_select_db($database) or die( "Unable to select database"); 

$id = $_GET['id'];
$newawb = $_GET['awbno'];
$newvsl = $_GET['vsl'];
$newcli = $_GET['cli'];
$newpcs = $_GET['pcs'];
$newwgt = $_GET['wgt'];
$newcar = $_GET['car'];
$newsnd = $_GET['snd'];
$newstt = $_GET['stt'];
$neward = $_GET['ard'];

$sql = "UPDATE tbl_import SET AwbNo='$newawb',ClientCode='$newcli',VesselName='$newvsl',Pieces='$newpcs',Weight='$newwgt',Carrier='$newcar',Sender='$newsnd',Status='$newstt',ArrivalDate='$neward',WHERE AwbNo='$id';"; 

echo ("id=$id,awb=$newawb,vsl=$newvsl,cli=$newcli,pcs=$newpcs,wgt=$newwgt,car=$newcar,send=$newsnd, status=$newstt, date=$neward .


");

mysql_query($sql)or die("Update Error: ".mysql_error());
mysql_close();        
//commented header so can see echoed vals sent from js
//header("Location: ../livedashboard.php"); //redirect to relevant page
  • 写回答

1条回答 默认 最新

  • dongxingji3882 2017-02-20 00:01
    关注

    First thing try to print:

    console.log('php/edit-livedashboard-import.php?id='+id+awb+del+vsl+cli+pcs+wgt+car+snd+stt+ard+ctm);
    

    it should be like this:

    'php/edit-livedashboard-import.php?id='+id+ '&awb='+awd+'&del='+del...etc;
    


    Second thing:

    Add full url instead of dir :

    window.location.href = 'php/edit-livedashboard-import.php?id='+id+aw...;
    

    ex.

    window.location.href = 'http://example.com/php/edit-livedashboard-import.php?id=...';
    
    评论

报告相同问题?

悬赏问题

  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值