Jump to content

header location works on localhost but not on actual server


Recommended Posts

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

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.

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);

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?

 

 

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.