douyinghuo8874 2015-01-25 22:22
浏览 27

按下编辑按钮时无法保持选择的下拉值

I've followed many tutorials on the internet about this so please don't ask me to search first, I already did that but still can't get this problem sorted out, this is my complete code:

<?php
include 'theme.php';
ceklogin();
$show=1;
if($_POST['delete']){
    $file_config=$_POST['config'];
    exec('rm -f /root/crt/'.$file_config);
    header( "refresh:0;url=vpn.php" );
    exit;
    }

if($_POST['apply']){
    exec('grep use_config /root/config |awk -F"\'" \'{print $2}\'',$y);
    $use_config=$_POST['use_config'];
    $file_config=$_POST['config'];
    if ($use_config=='yes'){
    exec('vpn use-config yes',$var);
    exec('vpn file-config '.$file_config,$var);
    header( "refresh:0;url=vpn.php" );
    exit;
    }
    else{
    exec('vpn use-config no',$var);
    exec('vpn file-config '.$file_config,$var);

    if($y[0]=='yes'){
    header( "refresh:0;url=vpn.php" );
    exit;
    }else{
    $server=$_POST['server'];
    $user=$_POST['user']; 
    $pass=$_POST['pass'];
    exec('vpn server '.$server,$var3);
    exec('vpn user-pass '.$user.' '.$pass,$var3);    
    header( "refresh:0;url=vpn.php" );
    exit;
    }}}

css();

    echo "
         <form action=\"upload_crt.php\" method=\"post\"
         enctype=\"multipart/form-data\">
        <label for=\"file\">file:</label>
        <input type=\"file\" name=\"file\" id=\"file\">
        <input type=\"submit\" name=\"upload\" value=\"Upload\">
        </form>";

    exec('cat /root/user.txt',$out);
    exec('vpn server show',$var1);
    exec('vpn config-show',$h);
    echo "<form action=\"".$PHP_SELF."\" method=\"post\">";
    echo "</br>";
    exec('grep use_config /root/config |awk -F"\'" \'{print $2}\'',$y);
    if ($y[0]=='yes'){
    echo '<input type="checkbox" name="use_config" value="yes" checked>Use file Config<br><br>';
    exec('ls /root/crt |grep -i -e .ovpn -e .txt',$list);
    echo 'Config: <select name="config">';
    $x=0;
    while($x<count($list)){   
    if($list[$x]==$h[0]){
    echo "<option value=\"/root/crt/$list[$x]\" selected>$list[$x]</option>";}
    else{echo "<option value=\"/root/crt/$list[$x]\">$list[$x]</option>";}
    $x++;
    }
    echo '<input name="edit" type="submit" value="Edit">';
    echo "<input name=\"delete\" type=\"submit\" value=\"Delete\"/>";

}
    else{echo '<input type="checkbox" name="use_config" value="yes" >Use file Config';

    echo "<br><br>Server: <input type=\"text\" name=\"server\" value=\"$var1[0]\"/>";
    echo " <br><br>";
    echo "User--: <input type=\"text\" name=\"user\" value=\"$out[0]\"/>";
    echo "<br><br>";
    echo "Pass--: <input type=\"password\" name=\"pass\" value=\"$out[1]\"/>";}
    echo "<br><br><input name=\"apply\" type=\"submit\" value=\"Apply Settings\"/>";
    echo '</form>';

if($_POST['edit']){
    $show=2;
    }
if ( $show == 1 )
{
if(isset($_POST["update"])) {
    file_put_contents($_POST['filename'], $_POST["akunvpn"]);
    $show=1;
    echo "<br><b><font color=\"green\">The file has been updated</font></b>";
 }
echo '<br><div style="font-size: 13px; word-wrap: break-word; width:400px;height:70px;border:0px solid #000;text-align:left; overflow-y: scroll;">
<b>NOTICE:</b> If you want your internet to be automatically reconnected when OpenVPN gets disconnected, add these lines in your *.ovpn :<br>
script-security 2 <br>
up client-connect.sh';
}
else {
    $filename = $_POST["config"];
    $filecontent = file_get_contents($filename);
    $nameonly = str_replace('/root/crt/', '', $filename);
    echo '<br><b><font color="green">Now editing: '.$nameonly.'</font></b>
    <br>
    <form action="" method="post">
    <textarea name="akunvpn" autofocus rows="12" cols="69" style="font-family: Arial;font-size: 9pt;">';
    echo htmlentities($filecontent);
    echo '</textarea><br><br>
    <input type="hidden" name="filename" value="'.$filename.'">
    <input name="update" type="submit" value="Update File">
    </form>
    '; //echos file content in textarea.
}
echo '
</div>
</div>';
foot();
echo '
</div>
</body>
</div>
</html>';
?>

I tried changing this part as suggested by many threads on the internet:

if($_POST['edit']){
    $show=2;
    echo '<option value="/root/crt/'.$_POST["update"].' selected >'.$_POST["update"].'</option>';
   } 

But the selected value always goes back to the top of the dropdown list when I click the edit button. Help.

enter image description here

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 链接问题 C++LNK2001 无法解析的外部符号
    • ¥50 安装pyaudiokits失败
    • ¥15 计组这些题应该咋做呀
    • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
    • ¥15 让node服务器有自动加载文件的功能
    • ¥15 jmeter脚本回放有的是对的有的是错的
    • ¥15 r语言蛋白组学相关问题
    • ¥15 Python时间序列如何拟合疏系数模型
    • ¥15 求学软件的前人们指明方向🥺
    • ¥50 如何增强飞上天的树莓派的热点信号强度,以使得笔记本可以在地面实现远程桌面连接