2014-09-13 115 views
0

此頁面正在重定向而不運行驗證過程,如果我註釋掉標題,則會重定向所有進程,因爲它們應該儘快將頁眉加載時自動重定向,這個頁面是從我創建的成員註冊頁面建模的,在沒有這個問題的情況下運行良好,所以我不能看到這個問題,請有人請客氣一點,以幫助我解決這個問題。頁面正在重定向而不運行進程

以下是標題標籤的頁面代碼註釋掉

<?php 
include_once 'functions.php'; 

    //Start session 
    sec_session_start(); 

    //Check whether the session variable SESS_MEMBER_ID is present or not 
    if(!isset($_SESSION['sess_user_id']) || (trim($_SESSION['sess_user_id']) == '')) { 
    header("location: login.php"); 
    exit(); 
    } 
    if(!isset($_SESSION['login']) == '1') { 
     header("location: admin_login.php"); 
     exit(); 
    } 
    ?> 
    <?php 
    //display users info with checkbox to delete 
$sql = "SELECT * FROM `links` LIMIT 0, 30 "; 
$result = mysqli_query($mysqli, $sql); 

?> 
    <?php 


// define variables and set to empty values 
$link_titleErr = $type_of_linkErr = $web_linkErr = ""; 
$link_title = $type_of_link = $web_link = ""; 

if ($_SERVER["REQUEST_METHOD"] == "POST") { 
    $link_title = test_input($_POST["link_title"]); 
    $type_of_link = test_input($_POST["select"]); 
    $web_link = test_input($_POST["web_link"]); 
} 


function test_input($data) { 
    $data = trim($data); 
    $data = stripslashes($data); 
    return $data; 
} 
if ($_SERVER["REQUEST_METHOD"] == "POST") { 
    if (empty($_POST["link_title"])) { 
    $link_titleErr = "**Link Title is required**"; 
    } else { 
    $link_title = test_input($_POST["link_title"]); 
     if (!preg_match("/^[a-zA-Z ]*$/",$link_title)) { 
     $link_titleErr = "**Only letters and white space allowed**"; 
    } 
    } 

    if (empty($_POST["web_link"])) { 
     $web_linkErr = "**Web Link is required**"; 
    } else { 
// do nothing 
    } 

      if($_POST['select'] == "") { 
       $type_of_linkErr = "**Type of Link is required**"; 
      } 
      else { 
       // do nothing 
      } 
     } 



    if ($link_titleErr == '' && $web_linkErr == '' && $type_of_linkErr == '') { 

    $_SESSION['data'] = array($_POST['link_title'],$_POST['web_link'],$_POST['type_of_link']); 
//header("Location: add_link.inc.php"); 
    }  

?> 

<!doctype html> 
<html> 
<head> 
<meta charset="utf-8"> 
<title>Add Links</title> 
<link href="../styles/main.css" rel="stylesheet" type="text/css"> 
</head> 



<div class="nav"><table width="100%" border="0" align="center" cellpadding="2" cellspacing="2"> 
    <tr> 
    <td width="20%" bgcolor="#980002"><div align="center"><a href="https://www.thamesvalleycoalition.co.uk/includes/admin_login.php" title="About Us" target="_self">ADMIN</a></div></td> 
    <td width="20%" bgcolor="#980002"><div align="center"><a href="https://www.thamesvalleycoalition.co.uk/includes/forum.php" title="Event Diary" target="_self">FORUM</a></div></td> 
    <td width="20%" bgcolor="#980002"><div align="center"><a href="https://www.thamesvalleycoalition.co.uk/includes/add_pictures.php" title="Photo Gallery" target="_self">ADD PICTURES</a></div></td> 
    <td width="20%" bgcolor="#980002"><div align="center"><a href="https://www.thamesvalleycoalition.co.uk/includes/add_links.php" title="Biker Friendly" target="_self">ADD LINKS</a></div></td> 
    <td width="%" bgcolor="#980002"><div align="center"><a href="https://www.thamesvalleycoalition.co.uk/includes/add_events.php" title="Links" target="_self">ADD EVENTS</a></div></td> 

    </tr> 
    <td height="4"></tr> 
</table> 
</div> 
<div class="subheader">ADD LINKS</div> 
<div class="header"><a href="https://thamesvalleycoalition.co.uk/includes/logout.php">logout</a></div> 

<div class="content"> 
    <div id="links_form"> 


    <form action="add_link.inc.php" method="post" id="links_form"> 
    <fieldset> 
     <legend>Add Link</legend> 
    <table width="100%"> 
    <tbody> 
     <tr> 
     <td width="33%"><div> 
      <div align="right">Link Title:</div> 
     </div></td> 
     <td width="33%"><div id="form_box"> 
      <input name="link_title" type="text" id="link_title" value="<?php echo $link_title;?>" size="40"> 
     </div></td> 
     <td width="33%"><div align="left"><span class="error" style="color: red"><?php echo $link_titleErr;?></span></div></td> 
     </tr> 
     <tr> 
     <td width="33%"><div align="right">Website Link:</div></td> 
     <td width="33%"><div id="form_box"> 
      <input name="web_link" type="text" id="web_link" value="<?php echo $web_link;?>" size="40"> 
     </div></td> 
     <td width="33%"><div align="left"><span class="error" style="color: red" ><?php echo $web_linkErr;?></span></div></td> 
     </tr> 
     <tr> 
     <td width="33%"><div align="right">Type of Business or Service:</div></td> 
     <td width="33%"><div id="form_box"> 
      <select name="select" id="select"> 
      <option value="">SELECT TYPE OF LINK</option> 
      <option value="Pub/Restaurant">Pub/Restaurant</option> 
      <option value="Shop/Store">Shop/Store</option> 
      <option value="Motorcycle/Car">Motorcycle/Car</option> 
      <option value="Other">Other</option> 
      </select> 
     </div></td> 
     <td width="33%"><div align="left"><span class="error" style="color: red"><?php echo $type_of_linkErr;?></span></div></td> 
     </tr> 
     <tr> 
     <td>&nbsp;</td> 
     <td><div align="center"> 
      <input type="submit" name="submit" id="submit" value="Add Link" formaction="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" formmethod="post"> 
     </div></td> 
     <td>&nbsp;</td> 
     </tr> 
    </tbody> 
    </table> 
    </fieldset> 
    </form> 
    </div> 
    <p>&nbsp;</p> 
    <div id="delete_link"><form><fieldset><legend>Delete Link</legend> 

      <?php while($row = mysqli_fetch_array($result)): ?> 
      <label> 
       <input type="checkbox" value="<?php echo $row['linkid']; ?>" name="delete[]" />    
       <?php echo $row['linkid']; ?> - <?php echo $row['link_title']; ?> - <?php echo $row['type_of_link']?> - <?php echo $row['web_link']?> <?php echo '<br/>'?> 

      </label> 
      <?php endwhile; ?> 
      <br> 
<input name="submit" type="submit" value="Delete Link" formmethod="post" formaction="delete_link.inc.php"/> 
      </p> 
      <p>&nbsp;</p> 
     </form> 

    </form></div> 
</div> 




<div class="footer" >All contents on this site are Copyright of the TVC.</div> 


</body> 
</html> 

回答

0

改變這一行:

if(!isset($_SESSION['login']) == '1') { 

if(isset($_SESSION['login']) && $_SESSION['login'] == '1') { 
+0

當我這樣做的改變發生的一切是爲重定向到登錄頁面,好像我沒有登錄到成員區域首先 – Tiny 2014-09-13 15:52:30

+0

嗯,好的,沒有你試着相反嗎? 'if(!isset($ _ SESSION ['login'])){' – RobbieP 2014-09-13 16:01:28

+0

剛剛嘗試過,它只是像以前一樣重定向 – Tiny 2014-09-13 16:33:57