du6029076877 2014-10-05 19:05
浏览 62
已采纳

从NULL传递NULL变量到Perl?

I have a php page that I'm using a form on and passing the selections/data that is made on the form to a perl script that I created. Unfortunately, when I pass the variables, if there are any empty variables my variables that I'm receiving on the perl script are not coming in at the right order. Is there a way to make sure the variables that are being passed to the perl script are being giving the correct order whether there's data in them or not?

<form action="index.php" method="post">
FTP/SFTP: <select name="TYPE">
    <option value="">Select...</option>
    <option value="ftpd">FTP</option>
    <option value="sftpd">SFTP</option>
</select></t><Br>
Search String: <input type="text" name="SEARCH"></t><br>
Search Type: <select name="STYPE">
    <option value="">Select...</option>
    <option value="user">Username</option>
    <option value="ip">IP Address</option>
    <option value="pid">PID</option>
    <option value="file">Filename</option>
</select><br>
Date (YYYY-MM-DD): <input type="text" name="DATE"></t><br>
Server: <select name="SERVER">
    <option value="">Select...</option>
    <option value="test1ftp">test1</option>
    <option value="test2ftp">test2</option>
</select></t><Br>

<input type="submit" name="formSearch" value="Search">

</form></font></p>

</body>
</html>

This is the php portion that is calling the perl script:

<?php       
    if(isset($_POST['formSearch']) == "Search")
    {
        if(empty($_POST['SEARCH']))
            $_POST['SEARCH'] = "undef";

        if(empty($_POST['SERVER']))
            $_POST['SERVER'] = "undef";

        if(empty($_POST['DATE']))
            $_POST['DATE'] = "undef";


        //system("perl search.pl $_POST[TYPE] $_POST[SEARCH] $_POST[STYPE] $_POST[DATE] $_POST[SERVER]", $return_val);


    }
?>

When it gets to the perl script, I have the variables that are being passed go to the following.

my $TYPE = $ARGV[0];
my $SEARCH = $ARGV[1];
my $STYPE = $ARGV[2];
my $DATE = $ARGV[3];
my $SYSTEM = $ARGV[4];

So if I have no data in SEARCH it seems that the data that should have been passed to $DATE now ends up in $SEARCH.

Any help would be appreciated.

Thank you.

  • 写回答

1条回答 默认 最新

  • dougai6464 2014-10-05 19:25
    关注

    Quote the command-line arguments. This will also be useful if the $_POST[...] variables have spaces in them:

    system("perl search.pl \"$_POST[TYPE]\" \"$_POST[SEARCH]\" \"$_POST[STYPE]\" \"$_POST[DATE]\" \"$_POST[SERVER]\"", $return_val);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题