Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ssl/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
通过Javascript保留页面更新并运行PHP代码?_Php_Javascript - Fatal编程技术网

通过Javascript保留页面更新并运行PHP代码?

通过Javascript保留页面更新并运行PHP代码?,php,javascript,Php,Javascript,在php项目中,我需要将项目添加到数据库中,列出它们并允许用户使用单个页面编辑和更新项目 这是我在HTML表中编辑项目链接的代码 echo '<a href=" '.$_SERVER['PHP_SELF'].'?name=edit&id=' .$rowCountry->CountryId .' " id="edit" onClick="MyFunction()"> Edit </a>'; echo'; 当用户单击上面的链接时,我需要隐藏添加按钮并

在php项目中,我需要将项目添加到数据库中,列出它们并允许用户使用单个页面编辑和更新项目

这是我在HTML表中编辑项目链接的代码

echo  '<a href="  '.$_SERVER['PHP_SELF'].'?name=edit&id='  .$rowCountry->CountryId .' " id="edit"  onClick="MyFunction()"> Edit </a>';
echo';
当用户单击上面的链接时,我需要隐藏
添加
按钮并显示两个新按钮以
更新
取消
编辑+在文本框中显示所选项目名称以进行编辑

为了隐藏和显示按钮,我使用jQuery,为了显示项目名称,我需要使用PHP。 在这里,当我放入PHP代码并使用
$\u SERVER['PHP\u SELF']
重新加载页面时(如上代码所示),页面加载后按钮的隐藏和显示将丢失。(如果我从链接中删除
\u服务器['PHP\u SELF']
代码,它会按预期隐藏和显示按钮(但不会运行PHP代码))

如何通过Javascript保留页面更新并运行PHP代码


我是PHP新手,我的代码中缺少什么吗?

$\u服务器['PHP\u SELF']只是对PHP文档本身的引用,它不包含任何键/值对。尝试使用:

echo  '<a href="  '.$_SERVER['PHP_SELF'].'?'. $_SERVER['QUERY_STRING'].
    '&name=edit&id='  .$rowCountry->CountryId .
        ' " id="edit" onClick="MyFunction()"> Edit </a>';
echo';
编辑: 我可能误解了这个问题。您可能需要这样的东西:

<?php
if(!empty($_GET[edit])){
    //echo code that u want to show AFTER they click the edit link
}else{
    //echo the code to show if they have NOT clicked the edit link
}
?>


感谢您的回答,实际上PHP代码运行良好,但页面加载时按钮的隐藏丢失。(我认为这是因为,它运行javascript客户端->隐藏按钮->在服务器中运行php代码->从服务器加载页面->按钮恢复原样)。您不需要使用jquery显示/隐藏它们。。。除非你使用ajax?