2012-10-06 25 views
0

我不希望这段代码在页面自动运行时运行。为什么这段代码仍在运行,尽管我已经允许这样做

//There was an identical id and request is somewhat real. (Still possible of a lucky guess) 
    if($array['isbeingwritten'] == 1) 
    { 
     //The article is already being written. 
     echo '<script type="text/javascript">alert("That article is being written. Someone beat you to it. You will now be redirected.");</script>'; 
     echo '<script type="text/javascript">window.location.href="write.php";</script>'; 
    } 

所以,我已经做到了这一点:

if(!isset($_POST['submit'])) 
{ 
    //There was an identical id and request is somewhat real. (Still possible of a lucky guess) 
    if($array['isbeingwritten'] == 1) 
    { 
     //The article is already being written. 
    echo '<script type="text/javascript">alert("That article is being written. Someone beat you to it. You will now be redirected.");</script>'; 
    echo '<script type="text/javascript">window.location.href="write.php";</script>'; 
    } 
} 

这是行不通的。它仍然按下提交后运行该代码!这里是我的形式:

  <form method="post" id="writearticle" action=""> 
       <textarea rows="30" cols="85" id="articlecontent" name="content" placeholder="Write the article here. Try to abide by the instructions and keywords provided." onkeyup="checkWordCount();" ></textarea> 
       <br />  
       <input type="submit" id="submit" name="submitarticle" value="Submit Article" class="submit" disabled />  

       <br /><br /><br /><br /><br /> 
      </form> 
+0

'NAME =“submitarticle”'你有没有名为“提交”领域,因此它永远不会被设置。 – Wiseguy

+0

谢谢。我总是很困惑我是否应该使用id或name .. – KriiV

回答

4

更改代码if(!isset($_POST['submit'])) to if(!isset($_POST['submitarticle']))