By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,948 Members | 852 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,948 IT Pros & Developers. It's quick & easy.

Doesn't Redirect After Successful Update

P: 22
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***
Expand|Select|Wrap|Line Numbers
  1. <?php include("includes/db_connect.php"); ?>
  2. <?php require_once("includes/functions.php"); ?>
  3.  
  4. <?php
  5.  
  6.     $equipid = mysqli_real_escape_string($db_cxn, trim(strip_tags($_POST['equipid'])));
  7.     $equipname = mysqli_real_escape_string($db_cxn, trim(htmlspecialchars($_POST['equipname'])));
  8.     $manufacturer = mysqli_real_escape_string($db_cxn, trim(htmlspecialchars($_POST['manufacturer'])));
  9.     $serno = mysqli_real_escape_string($db_cxn, trim(htmlspecialchars($_POST['serno'])));
  10.     $modelno = mysqli_real_escape_string($db_cxn, trim(htmlspecialchars($_POST['modelno'])));
  11.     $capacity = mysqli_real_escape_string($db_cxn, trim(htmlspecialchars($_POST['capacity'])));
  12.     $curloc = mysqli_real_escape_string($db_cxn, trim(strip_tags($_POST['curlocation'])));
  13.     $equipcode = mysqli_real_escape_string($db_cxn, trim(strip_tags($_POST['equipcode'])));
  14.     $seqno = mysqli_real_escape_string($db_cxn, trim(strip_tags($_POST['seqno'])));    
  15.     $addDate = mysqli_real_escape_string($db_cxn, trim(strip_tags($_POST['adddate'])));
  16.  
  17.  
  18.     $query_update = "UPDATE `tblequipmentmasterlist` SET ";
  19.     $query_update .= "`equipname` = '{$equipname}', ";
  20.     $query_update .= "`manufacturer` = '{$manufacturer}', ";
  21.     $query_update .= "`serno` = '{$serno}', ";
  22.     $query_update .= "`modelno` = '{$modelno}', "; 
  23.     $query_update .= "`capacity` = '{$capacity}', "; 
  24.     $query_update .= "`curlocation` = '{$curloc}', "; 
  25.     $query_update .= "`equipcode` = '{$equipcode}', "; 
  26.     $query_update .= "`seqno` = '{$seqno}', "; 
  27.     $query_update .= "`adddate` = '{$addDate}' ";
  28.     $query_update .= "WHERE `tblequipmentmasterlist`.`equipid` = {$equipid} LIMIT 1";
  29.  
  30.     $result = mysqli_query($db_cxn, $query_update);
  31.  
  32.     if (mysqli_affected_rows($db_cxn) == 1) {
  33.         header ("LOCATION : updatedata.php"); //Record was successfully updated
  34.     } else {
  35.         print_r($_POST);
  36.         var_dump($_POST);
  37.         echo "<p>Update failed : <br />". $query_update.  " <br/>Please contact the site administrator.</p>";
  38.         echo "<p>" . mysqli_error($db_cxn) . "</p>";
  39.     }
  40.  
  41. ?>
  42.  
  43. <?php 
  44.     if (isset($db_cxn)) {
  45.         mysqli_close($db_cxn); 
  46.     }
  47. ?>
  48.  
Oct 10 '11 #1

✓ answered by YarrOfDoom

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.

Share this Question
Share on Google+
1 Reply


YarrOfDoom
Expert 100+
P: 1,247
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.
Oct 10 '11 #2

Post your reply

Sign in to post your reply or Sign up for a free account.