PHP表内联编辑 - Javascript函数

时间:2017-02-19 23:51:24

标签: javascript php html

我正在尝试在我的桌面上创建内联编辑功能,用户应该能够重新键入值,然后点击“保存”。按钮更新数据库记录。

我遇到了javascript函数的问题,它没有按照< window.location.href'来恢复到下一页,这将是php update qry页面,它还原我回到原始页面查看所做的更改。

javascript函数用于获取旧ID,以及记录中可能已内联编辑的所有新td。

我有这个工作用于id本身,但是添加了所有新值,ive搞砸了js函数或动作但是(可能'这个'?)不完全确定。我知道mysql是垃圾等等,我现在专注于功能。

JS功能

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;}

表格操作按钮

$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 .\n\n\n");

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 个答案:

答案 0 :(得分:0)

首先尝试打印:

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

它应该是这样的:

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


第二件事:

添加完整网址而不是目录:

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

离。

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