I ran into the same problem. The new node stores WAS in my database, but DOES NOT update the name of the node or node. I started Firebug.php and saw that the newly created node id (mysqli_insert_id) was not passed to rename_node.
I decided to use session variables — set a variable to indicate that the rename function was available from create_node, as well as set the last_id session variable.
"CRN" is just a variable specific to my database and application, you can ignore it.
So, using the provided response.php example, I modified it like this:
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;
source share