Doesn't Redirect After Successful Update

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Antonio Bacasno
    New Member
    • Sep 2011
    • 22

    Doesn't Redirect After Successful Update

    Can somebody please help me? I would like to redirect to a new page once a successful update was performed, but my redirect code doesn't work. After a successful update, it doesn't perform the redirect, instead it opens up a blank version of the current page. Can somebody please check my code and see what's wrong with it? Thanks.

    ***AFTER A SUCCESSFUL UPDATE, IT OPENS UP A BLANK VERSION OF THIS PAGE INSTEAD OF REDIRECTING TO UPDATEDATA.PHP* **
    Code:
    <?php include("includes/db_connect.php"); ?>
    <?php require_once("includes/functions.php"); ?>
    
    <?php
    
    	$equipid = mysqli_real_escape_string($db_cxn, trim(strip_tags($_POST['equipid'])));
    	$equipname = mysqli_real_escape_string($db_cxn, trim(htmlspecialchars($_POST['equipname'])));
    	$manufacturer = mysqli_real_escape_string($db_cxn, trim(htmlspecialchars($_POST['manufacturer'])));
    	$serno = mysqli_real_escape_string($db_cxn, trim(htmlspecialchars($_POST['serno'])));
    	$modelno = mysqli_real_escape_string($db_cxn, trim(htmlspecialchars($_POST['modelno'])));
    	$capacity = mysqli_real_escape_string($db_cxn, trim(htmlspecialchars($_POST['capacity'])));
    	$curloc = mysqli_real_escape_string($db_cxn, trim(strip_tags($_POST['curlocation'])));
    	$equipcode = mysqli_real_escape_string($db_cxn, trim(strip_tags($_POST['equipcode'])));
    	$seqno = mysqli_real_escape_string($db_cxn, trim(strip_tags($_POST['seqno'])));	
    	$addDate = mysqli_real_escape_string($db_cxn, trim(strip_tags($_POST['adddate'])));
    	
    	
    	$query_update = "UPDATE `tblequipmentmasterlist` SET ";
    	$query_update .= "`equipname` = '{$equipname}', ";
    	$query_update .= "`manufacturer` = '{$manufacturer}', ";
    	$query_update .= "`serno` = '{$serno}', ";
    	$query_update .= "`modelno` = '{$modelno}', "; 
    	$query_update .= "`capacity` = '{$capacity}', "; 
    	$query_update .= "`curlocation` = '{$curloc}', "; 
    	$query_update .= "`equipcode` = '{$equipcode}', "; 
    	$query_update .= "`seqno` = '{$seqno}', "; 
    	$query_update .= "`adddate` = '{$addDate}' ";
    	$query_update .= "WHERE `tblequipmentmasterlist`.`equipid` = {$equipid} LIMIT 1";
    	
    	$result = mysqli_query($db_cxn, $query_update);
    	
    	if (mysqli_affected_rows($db_cxn) == 1) {
    		header ("LOCATION : updatedata.php"); //Record was successfully updated
    	} else {
    		print_r($_POST);
    		var_dump($_POST);
    		echo "<p>Update failed : <br />". $query_update.  " <br/>Please contact the site administrator.</p>";
    		echo "<p>" . mysqli_error($db_cxn) . "</p>";
    	}
    		
    ?>
    
    <?php 
    	if (isset($db_cxn)) {
    		mysqli_close($db_cxn); 
    	}
    ?>
  • YarrOfDoom
    Recognized Expert Top Contributor
    • Aug 2007
    • 1243

    #2
    From the php manual on header():
    HTTP/1.1 requires an absolute URI as argument to ยป Location: including the scheme, hostname and absolute path, but some clients accept relative URIs. You can usually use $_SERVER['HTTP_HOST'], $_SERVER['PHP_SELF'] and dirname() to make an absolute URI from a relative one yourself.
    You also left a space after "Location", before the colon. I don't think that's allowed either.

    Comment

    Working...