普通网友 2013-03-25 04:27
浏览 16

未验证其中一个搜索字段

I want to check if either of my search fields are empty, and if they are i write out a failure message. For some reason the following code doesn't work when I try to submit empty values in both search fields, or leaving the q2 search field empty. It only writes out the failure message when I only insert a value into the first field. Hope you guys can help.

<div id="searchField">
    <form name="searchField" action="" method="get">
        <input type="search" name="q" id="submitQuery" autofocus="autofocus" value="<?= $_GET['q']; ?>" placeholder="enter one movie"/> 
        <input type="search" name="q2" id="submitQuery2" value="<?= $_GET['q2']; ?>" placeholder="and then another one"/> 
        <input type="hidden" id="v" name="v" value="2" />
        <input type="hidden" id="b" name="b" value="" />
        <button type="submit" id="loop" style="border:0px; background:transparent; vertical-align:middle; margin-left:-85px; margin-top:-3px;">
            <img src="images/loop.png" width="75" height="75" alt="submit" />       
        </button>
    </form>
</div>
<div id="theData">

<?
if(str_replace(" ", "",$_GET['q'])!="" && str_replace(" ","",$_GET['q2'])!=""){
    $qContent = $_GET['q'];
    $succes = mysql_query("SELECT*FROM film WHERE name='".$qContent."'");
    include("searchMaster.php");
    if(mysql_num_rows($succes)) {
        while($o = mysql_fetch_array($succes)){
            echo $o['name'];
            if($o['trailer']){
                echo '<div id="ytplayerWrap">';
                echo '<iframe id="ytplayer" type="text/html" width="640" height="390"
                src="http://www.youtube.com/embed/'.$o['trailer'].'?http://amnestic.ueuo.com"
                frameborder="0"/>';
                echo '</div>';
            }else {
                echo '<span style="font-size:20px;">';
                echo '<br /><br /> No trailer was found for <em>'.$_GET['q'].'</em> :(';
                echo '</span>';
            }
        }
    }else{
     echo 'You did the fuckup :(';
    }
}else{
echo 'You did the fuckup :(';
}
?>
  • 写回答

1条回答 默认 最新

  • douzhuo6270 2013-03-25 04:29
    关注

    The name and id of your input fields must be same Like this

    <input type="text" name="submitQuery" id="submitQuery" autofocus="autofocus" value="<?= $_GET['q']; ?>" placeholder="enter one movie"/> 
    <input type="text" name="submitQuery2" id="submitQuery2" value="<?= $_GET['q2']; ?>" placeholder="and then another one"/> 
    
    评论

报告相同问题?

悬赏问题

  • ¥15 运动想象脑电信号数据集.vhdr
  • ¥15 三因素重复测量数据R语句编写,不存在交互作用
  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目