我遇到了同样的问题。新节点存储在我的数据库中,但不更新节点名称或节点文本。我运行 Firebug.php 并看到新创建的节点 ID (mysqli_insert_id) 没有被传递给 rename_node。
我使用会话变量解决了它 - 设置一个变量以指示从 create_node 访问重命名函数并设置一个“last_id”会话变量。
'CRN' 只是我的数据库和应用程序特有的变量,您可以忽略它。
因此,使用提供的 response.php 示例,我对其进行了如下修改:
case 'create_node':
FB::info($_GET, "New Node attributes ");
$node = isset($_GET['id']) && $_GET['id'] !== '#' ? (int)$_GET['id'] : 0;
$nodeText = isset($_GET['text']) && $_GET['text'] !== '' ? $_GET['text'] : '';
$CRN=$_SESSION['CRN'];
$sql ="INSERT INTO CourseLookup (name, text, parent_id, CRN) VALUES('$nodeText','$nodeText','$node','$CRN')";
FB::info($sql, "new node query ");
mysqli_query($conn, $sql);
$last_id = mysqli_insert_id($conn);
$_SESSION['create']=true;//passed to rename_node so it knows to use the $last_id for the node
$_SESSION['lastid']=$last_id;//used as the node in rename_node
$result = array('id' => $last_id);
print_r($result);die;
break;
case 'rename_node':
if($_SESSION['create']){//if a new node was just created
$node=$_SESSION['lastid'];//use the last insert id
}
else{
$node = isset($_GET['id']) && $_GET['id'] !== '#' ? (int)$_GET['id'] : 0;//otherwise use the last menu item clicked
}
FB::info($_SESSION['create'],"create status");//debugging
FB::info($_SESSION['lastid'],"last id");//debuggig
//print_R($_GET);
$nodeText = isset($_GET['text']) && $_GET['text'] !== '' ? $_GET['text'] : '';
FB::info($nodeText, "node name ");
$sql ="UPDATE CourseLookup SET name='$nodeText', text='$nodeText' WHERE id=$node";
FB::info($sql, "rename node query ");
mysqli_query($conn, $sql);
$_SESSION['create']=false;
break;