This is topic PHP coding help in forum Film-Yak at Film-Tech Forum ARCHIVE.
To visit this topic, use this URL:
https://ft-forum.com/ft/cgi-bin/ubb/ultimatebb.cgi?ubb=get_topic;f=8;t=005287
Posted by Andrew McCrea (Member # 674) on 12-01-2007, 09:42 AM:
Hello!
I'm learning PHP right now (from "PHP and MySQL for Dummies").
I've been using some of their code examples in the book to build the member's only section.
I was wondering if anyone could help me figure out why this page won't load to the next member_page.php.
This is the code to the Login page (I removed the registering opion):
[CODE]<?php
/* Program: Login.php
* Desc: Login program for the Members Only section of
* the pet store. It provides two options:
* (1) login using an existing Login Name and
*/
session_start(); # 9
include("connect.inc"); #10
switch (@$_POST['do']) #11
{
case "login": #13
$cxn = mysqli_connect($host,$user,$passwd,$dbname)
or die ("Couldn't connect to server."); #15
$sql = "SELECT loginName FROM member
WHERE loginName='$_POST[fusername]'"; #18
$result = mysqli_query($cxn,$sql)
or die("Couldn't execute query."); #20
$num = mysqli_num_rows($result); #21
if ($num > 0) // login name was found #22
{
$sql = "SELECT loginName FROM member
WHERE loginName='$_POST[fusername]'
AND password=md5('$_POST[fpassword]')";
$result2 = mysqli_query($cxn,$sql)
or die("Couldn't execute query 2.");
$num2 = mysqli_num_rows($result2);
if ($num2 > 0) // password is correct #30
{
$_SESSION['auth']="yes"; #32
$logname=$_POST['fusername'];
$_SESSION['logname'] = $logname; #34
$today = date("Y-m-d h:i:s"); #35
$sql = "INSERT INTO login (loginName,loginTime)
VALUES ('$logname','$today')";
$result = mysqli_query($cxn,$sql)
or die("Can't execute insert query.");
header("Location: member_page.php"); #40
}
else // password is not correct #42
{
$message="The Login Name, '$_POST[fusername]'
exists, but you have not entered the
correct password! Please try again.<br>";
include("login_form.inc"); #47
}
} #49
elseif ($num == 0) // login name not found #50
{
$message = "The Login Name you entered does not
exist! Please try again.<br>";
include("login_form.inc");
}
break; #56
default: #223
include("login_form.inc");
}
?>
[/CODE]
Posted by Roger Summars (Member # 4494) on 12-03-2007, 11:10 AM:
just a quick shot-in-the-dark here....
Have you thought about changing line 40 to include the full URL, such as:
header('Location: http://www.myexample.com/member_page.php');
Note I changed to single quotes also, you might have to try it both ways.
Roger
Posted by Mark J. Marshall (Member # 1409) on 12-03-2007, 11:57 AM:
Relative paths should work with the header() function, however if you're calling it from within an include file, remember that the relative path that you need is not the relative path from the included file, but from the main file. This is why I always try to have the full path there, including the "http://" or "https://".
Also, from PHP.net:
quote:
Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP. It is a very common error to read code with include(), or require(), functions, or another file access function, and have spaces or empty lines that are output before header() is called. The same problem exists when using a single PHP/HTML file.
That means check your "connect.inc" file (and this file) for any blank lines or other output. There can't be anything sent to the browser before the header() function is called.
Powered by Infopop Corporation
UBB.classicTM
6.3.1.2