futrose Posted February 28, 2011 Share Posted February 28, 2011 I was hoping someone could help me figure out why my header('Location: .'); works right on my localhost testing computer but not when I load it onto the actual server. Here are the two files in question. The first is a snippet from my index.php controller file. if (isset($_POST['action']) and $_POST['action'] == 'Edit') { include '../../includes/db.inc.php'; { $id = mysqli_real_escape_string($link, $_POST['id']); $sql = "Select * from s_times where id = '$id'"; $result = mysqli_query($link, $sql); if (!$result) { $error = 'Error fetching service time details ' . mysqli_error($link); include '../../includes/error.php'; exit(); } $row = mysqli_fetch_array($result); $pagetitle = 'Edit Category'; $action = 'editform'; $id = $row['id']; $day = $row['day']; $time = $row['time']; $event = $row['event']; $avail = $row['avail']; $orderby = $row['orderby']; $button = 'Update'; } include 'stimes_modify.php'; exit(); } if (isset($_GET['editform'])) { include '../../includes/db.inc.php'; $id = mysqli_real_escape_string($link, $_POST['id']); $day = mysqli_real_escape_string($link, $_POST['day']); $time = mysqli_real_escape_string($link, $_POST['time']); $event = mysqli_real_escape_string($link, $_POST['event']); $avail = mysqli_real_escape_string($link, $_POST['available']); $orderby = mysqli_real_escape_string($link, $_POST['orderby']); $sql = "Update s_times set day = '$day', time = '$time', event = '$event', avail = '$avail', orderby = '$orderby' where id = '$id'"; if (!mysqli_query($link, $sql)) { $error = 'Error updating service times ' . mysqli_error($link); include '../../includes/error.php'; exit(); } header('Location: .'); exit(); } here is the stimes_modify.php file code if (isset($_POST['action']) and $_POST['action'] == 'Edit') { include '../../includes/db.inc.php'; { $id = mysqli_real_escape_string($link, $_POST['id']); $sql = "Select * from s_times where id = '$id'"; $result = mysqli_query($link, $sql); if (!$result) { $error = 'Error fetching service time details ' . mysqli_error($link); include '../../includes/error.php'; exit(); } $row = mysqli_fetch_array($result); $pagetitle = 'Edit Category'; $action = 'editform'; $id = $row['id']; $day = $row['day']; $time = $row['time']; $event = $row['event']; $avail = $row['avail']; $orderby = $row['orderby']; $button = 'Update'; } include 'stimes_modify.php'; exit(); } if (isset($_GET['editform'])) { include '../../includes/db.inc.php'; $id = mysqli_real_escape_string($link, $_POST['id']); $day = mysqli_real_escape_string($link, $_POST['day']); $time = mysqli_real_escape_string($link, $_POST['time']); $event = mysqli_real_escape_string($link, $_POST['event']); $avail = mysqli_real_escape_string($link, $_POST['available']); $orderby = mysqli_real_escape_string($link, $_POST['orderby']); $sql = "Update s_times set day = '$day', time = '$time', event = '$event', avail = '$avail', orderby = '$orderby' where id = '$id'"; if (!mysqli_query($link, $sql)) { $error = 'Error updating service times ' . mysqli_error($link); include '../../includes/error.php'; exit(); } header('Location: .'); exit(); } The functionality of both pages seems to be working in relation to editing the database but the page will not redirect back to the main page when it gets back down to the header line. Like I said it works on localhost just not on actual server. I also tried putting in the full URL like this header('Location: http://www.bbcpa.org/dbsite/admin/stimes/stimes/php'); and still got a blank page. The URL in the address bar shows this http://www.bbcpa.org/dbsite/admin/stimes/?editform it should show this http://www.bbcpa.org/dbsite/admin/stimes/ so maybe something is wrong with this line in stimes_modify.php <form action="?<?php htmlout($action); ?>" method="POST"> anyway any help would be greatly appreciated. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/229128-header-location-works-on-localhost-but-not-on-actual-server/ Share on other sites More sharing options...
PFMaBiSmAd Posted February 28, 2011 Share Posted February 28, 2011 Do you have error_reporting set to E_ALL and display_errors set to ON so that php detected errors would be reported and displayed? Quote Link to comment https://forums.phpfreaks.com/topic/229128-header-location-works-on-localhost-but-not-on-actual-server/#findComment-1180743 Share on other sites More sharing options...
futrose Posted February 28, 2011 Author Share Posted February 28, 2011 No I don't, well I'm not sure. What file is that usually in so I can try and check it. The site is hosted on a hosting companies server so I'm not sure what config/ini files I have access to. Quote Link to comment https://forums.phpfreaks.com/topic/229128-header-location-works-on-localhost-but-not-on-actual-server/#findComment-1180745 Share on other sites More sharing options...
futrose Posted February 28, 2011 Author Share Posted February 28, 2011 sorry, i realized that i could check those settings on my localhost computer since it may be working on here if those are off. I will check them and repost. Quote Link to comment https://forums.phpfreaks.com/topic/229128-header-location-works-on-localhost-but-not-on-actual-server/#findComment-1180751 Share on other sites More sharing options...
futrose Posted February 28, 2011 Author Share Posted February 28, 2011 Ok both error_reporting is set to E_ALL and display_errors is set to ON on my local computer and I get no errors when I run the code on localhost. Only thing returned from header('Location: .'); on the hosting server is a blank page with no source code either. I don't know what the error_reporting and display_errors are set to on the host machine. Quote Link to comment https://forums.phpfreaks.com/topic/229128-header-location-works-on-localhost-but-not-on-actual-server/#findComment-1180753 Share on other sites More sharing options...
PFMaBiSmAd Posted February 28, 2011 Share Posted February 28, 2011 Assuming that you don't have a fatal parse error in your main file, you can add the following two lines immediately after your first opening <?php tag to set those values in your script - ini_set("display_errors", "1"); error_reporting(-1); Quote Link to comment https://forums.phpfreaks.com/topic/229128-header-location-works-on-localhost-but-not-on-actual-server/#findComment-1180760 Share on other sites More sharing options...
futrose Posted March 1, 2011 Author Share Posted March 1, 2011 ok so this is what I got after I added those ini lines Warning: Cannot modify header information - headers already sent by (output started at /services5/webpages/util/b/b/bbctech2.site.aplus.net/public/dbinfo.inc.php:5) in /services5/webpages/util/b/b/bbctech2.site.aplus.net/public/dbsite/admin/stimes/index.php on line 103 this is all that is in my dbinfo.inc.php file <? $user="**********"; $password="************"; $database="***************"; ?> and line 103 of index.php is the line in question. header('Location: .'); so apparently I need to rework this bit of code correct? if (isset($_GET['editform'])) { include '../../includes/db.inc.php'; $id = mysqli_real_escape_string($link, $_POST['id']); $day = mysqli_real_escape_string($link, $_POST['day']); $time = mysqli_real_escape_string($link, $_POST['time']); $event = mysqli_real_escape_string($link, $_POST['event']); $avail = mysqli_real_escape_string($link, $_POST['available']); $orderby = mysqli_real_escape_string($link, $_POST['orderby']); $sql = "Update s_times set day = '$day', time = '$time', event = '$event', avail = '$avail', orderby = '$orderby' where id = '$id'"; if (!mysqli_query($link, $sql)) { $error = 'Error updating service times ' . mysqli_error($link); include '../../includes/error.php'; exit(); } header('Location: .'); exit(); } so that the dbinfo.inc.php include comes after the header... line? Any ideas? Am I on the right track? Quote Link to comment https://forums.phpfreaks.com/topic/229128-header-location-works-on-localhost-but-not-on-actual-server/#findComment-1181011 Share on other sites More sharing options...
PFMaBiSmAd Posted March 1, 2011 Share Posted March 1, 2011 You have a new-line character after the closing ?> tag in dbinfo.inc.php. Remove everything in dbinfo.inc.php that is after the closing ?> tag. Quote Link to comment https://forums.phpfreaks.com/topic/229128-header-location-works-on-localhost-but-not-on-actual-server/#findComment-1181014 Share on other sites More sharing options...
futrose Posted March 1, 2011 Author Share Posted March 1, 2011 I have no idea how you saw that but thank you. That took care of that issue. Quick question. Is there any reason that the 2 lines of code you gave me to use ini_set("display_errors", "1"); error_reporting(-1); are making my pages not load correctly on my localhost testing server? Does it just have to do with the ini and config settings? I can remove the lines from the files on my local computer, it isn't a big deal. I'm just getting different errors live than I am on the local machine. Is that a problem you think? For example on my local machine I get Fatal error: Call to undefined function mysqli_connect() in C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\includes\db.inc.php on line 2 but on the live server I don't get that error. Quote Link to comment https://forums.phpfreaks.com/topic/229128-header-location-works-on-localhost-but-not-on-actual-server/#findComment-1181017 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.