Form not redirecting

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
Maugrim_The_Reaper
DevNet Master
Posts: 2704
Joined: Tue Nov 02, 2004 5:43 am
Location: Ireland

Post by Maugrim_The_Reaper »

If SID contains a string of format "?foo=bar" it should be fine - if SID however is just a session id, or something else you will need to manually add the "?foo=".SID.
TheOracle
Forum Commoner
Posts: 64
Joined: Mon Nov 22, 2004 4:56 am
Location: Bedford, UK

Post by TheOracle »

To be honest I'm not entirely sure, as I took the majority of this code from a book. I have just been trying to tweak it for my own needs. I think it has something to do with Session ID, but I can't find anything in the functions which point to it.

Regardless of this, it is not causing the problem, as I have tried removing it and the page still just refreshes. It must be something very fundamental but also very simple I'm sure, I just can't work it out?
User avatar
Maugrim_The_Reaper
DevNet Master
Posts: 2704
Joined: Tue Nov 02, 2004 5:43 am
Location: Ireland

Post by Maugrim_The_Reaper »

Let's try another approach - assuming you have Firefox. Do IE6 and Firefox both refresh the page the same way?

Also, if possible - give the js a shot...:) Might be surprising...
rehfeld
Forum Regular
Posts: 741
Joined: Mon Oct 18, 2004 8:14 pm

Post by rehfeld »

whats your error_reporting set to?

try adding this at the VERY beggining of the script. BEFORE any includes, the very first line.

Code: Select all

<?php
error_reporting(E_ALL);
?>
let us know what happens
TheOracle
Forum Commoner
Posts: 64
Joined: Mon Nov 22, 2004 4:56 am
Location: Bedford, UK

Post by TheOracle »

OK, some errors!

Notice: Undefined variable: link in C:\phpWeb\Right-Track\includes\dbconn.inc on line 2

Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at C:\phpWeb\Right-Track\includes\dbconn.inc:2) in C:\phpWeb\Right-Track\includes\funclib.inc on line 3

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\phpWeb\Right-Track\includes\dbconn.inc:2) in C:\phpWeb\Right-Track\includes\funclib.inc on line 3

Warning: Cannot modify header information - headers already sent by (output started at C:\phpWeb\Right-Track\includes\dbconn.inc:2) in C:\phpWeb\Right-Track\includes\funclib.inc on line 4


Just so you can see, my 2 include files:

funclib.inc

Code: Select all

<?php
session_start();
header('Cache-Control: public'); 

function cleanMemberSession($id, $login, $pass)
	{
	$_SESSION[id] = $id;
	$_SESSION[login] = $login;
	$_SESSION[password] = $pass;
	$_SESSION[logged_in] = true;
	}
	
?>
dbconn.inc

Code: Select all

<?php
$link;
connectToDB();
function connectToDB()
	{
	global $link;
	$link = mysql_connect("localhost","root","quiksilver");
	if(!$link)
		die("Could not connect to MySQL");
	mysql_select_db("righttrack", $link);	

	}
	
function newUser($login, $pass)
	{
	global $link;
	$result=mysql_query("insert into user_details (username, password)
						values('$login', '$pass')", $link);
	return mysql_insert_id($link);
	}
	
function getRow($table, $fnm, $fval) 
	{ 
    global $link; 
    $result=mysql_query("select * from $table where $fnm='$fval'", $link); 
    if(!$result) 
        die("getRow fatal error: " .mysql_error()); 
    return mysql_fetch_array($result); 
}
?>
Not sure what all this means. I've probably messed up big time, but any advice appreciated.

Thanks.

?>
User avatar
Maugrim_The_Reaper
DevNet Master
Posts: 2704
Joined: Tue Nov 02, 2004 5:43 am
Location: Ireland

Post by Maugrim_The_Reaper »

This why I prefer JS or meta refreshes to Header...

Warning: Cannot modify header information - headers already sent by (output started at C:\phpWeb\Right-Track\includes\dbconn.inc:2) in C:\phpWeb\Right-Track\includes\funclib.inc on line 4

If output has already started - you cannot use Header(). Headers are sent prior to the body of the page - which means even a single character outputted will block any headers sent afterwards.

JS on the other hand is unaffected by this. I'd suggest at least testing it as per my prior suggestion in place of the header...

I also see now why SID is being sent by url - can't set a cookie after something is outputted either...
TheOracle
Forum Commoner
Posts: 64
Joined: Mon Nov 22, 2004 4:56 am
Location: Bedford, UK

Post by TheOracle »

Ok, so I need to remove the header in my funclib.inc file? and also the header redirects in my main page?

And can you just confirm what the .SID was doing, and where it was getting its info. Is it a standard variable when using session_start()?
TheOracle
Forum Commoner
Posts: 64
Joined: Mon Nov 22, 2004 4:56 am
Location: Bedford, UK

Post by TheOracle »

I'm also getting:

Notice: Undefined variable: login in C:\phpWeb\Right-Track\auth.php on line 211

This is appearing in the username box!!!
TheOracle
Forum Commoner
Posts: 64
Joined: Mon Nov 22, 2004 4:56 am
Location: Bedford, UK

Post by TheOracle »

Ok, so I now put in ob_start(); before my includes and the header errors have gone away. The 2 undefined variables link, and login are still there.

If I add in the correct details and submit again, I get the following errors:

Notice: Undefined variable: link in C:\phpWeb\Right-Track\includes\dbconn.inc on line 2

Notice: Undefined variable: message in C:\phpWeb\Right-Track\auth.php on line 29

Notice: Use of undefined constant id - assumed 'id' in C:\phpWeb\Right-Track\includes\funclib.inc on line 7

Notice: Use of undefined constant login - assumed 'login' in C:\phpWeb\Right-Track\includes\funclib.inc on line 8

Notice: Use of undefined constant password - assumed 'password' in C:\phpWeb\Right-Track\includes\funclib.inc on line 9

Notice: Use of undefined constant logged_in - assumed 'logged_in' in C:\phpWeb\Right-Track\includes\funclib.inc on line 10

Notice: Undefined index: button in C:\phpWeb\Right-Track\auth.php on line 33

Notice: Undefined index: button in C:\phpWeb\Right-Track\auth.php on line 38

Notice: Undefined index: button in C:\phpWeb\Right-Track\auth.php on line 43

Notice: Undefined index: button in C:\phpWeb\Right-Track\auth.php on line 48

Notice: Undefined index: button in C:\phpWeb\Right-Track\auth.php on line 53

Notice: Undefined index: button in C:\phpWeb\Right-Track\auth.php on line 58


This obviously shows that something is wrong with the button varibale.

I have changed the headers to the JS as suggested aswell.
TheOracle
Forum Commoner
Posts: 64
Joined: Mon Nov 22, 2004 4:56 am
Location: Bedford, UK

Post by TheOracle »

Would undefined index mean that it is not set? In which case, how can I get it to set? I am going though from the front page and the URL says auth.php?button=2

I'm really struggling with this now, please help me get it sorted. Thanks.
TheOracle
Forum Commoner
Posts: 64
Joined: Mon Nov 22, 2004 4:56 am
Location: Bedford, UK

Post by TheOracle »

Do I need anything PHP wise on the front page where I'm passing ?button=1 from? I thought I could just set the link to auth.php?button=1 - Would I have to declare this somewhere?
Post Reply