PDA

View Full Version : PHP Code Help



trinski
12-23-2003, 12:03 PM
I am currently implementing an object-oriented programming in PHP. The files are compiling (not really compiling, what's a better word for this?) but when I clicked on my link it doesn't work.

I use .html with php implementation. What happened is that when I clicked the link member.php?service=register when $_POST['submit'] is not set the register.html doesn't show up. @file_get_contents echoes the register form.

When I made a test file using the functions in the .php files, they work; but when I implemented on this code it doesn't.

Sorry for the long code. Thanks! :)


Here's my code:

<?php



set_magic_quotes_runtime(0);
ignore_user_abort(false);


require_once('registerFunctions.php');
require_once('errorFunctions.php');
require_once('commonFunctions.php');
require_once('userManager.php');
// require_once('languageDetector.php');


if(!isset($_GET['service'])) {

$_GET['service'] = '';
}

switch($_GET['service']) {

case 'login':

// Is the login from the login dialogue box?
// If it is, check entered values,
// get userID, check if member is verified,
// log in user, see member's permissions;
// else, return to index.html. [!!!]

if(!isset($_POST['submit'])) {

$index = @file_get_contents('templates/
dialogueBoxes.login.html' .
'dialogueBoxes.login.html');

echo $index;

} else {

if(validateInput() == false) {

echo 'Please check your values.';
}
if(loginUser() == false) {

generateError(0, 0, 'Login failed.');
}
if($status = loginUser($memberID, $password,
$verificationCode)) {

switch($status) {

case 0:

// If tagContentID is 1
// and tag has verification code.

return ('Login successful! Login!');
break;
case 1:

// If tagContentID is 0 and tag
// has verification code.

return ('Need your vericode. Enter it here.');
break;
case 2:

// If tagContentID is 0 and
// tag is not equal to code.

return ('Check your verification code again');
break;
case 3:

// If tagContentID is 0 and tag
// is equal to code.

return ('User verified. Login!');
}
}
if(isLoggedIn() == false) {

generateError(0, 0, 'Unable to log in.');
} else {

$index = @file_get_contents('templates/
dialogueBoxes.login.html' .
'dialogueBoxes.login.html');

echo $index;
}
}
break;
case 'register':

// Is the link member.php?service=register
// from register.html?
// If not, show register.html;
// else, check if user is registered.
// Did the user click on the button?
// if not, return to register.html;
// else, check if registration was
// successful and if inputs were
// valid.

if(isset($_POST['submit'])) {

if(validateInput() == false) {

echo 'Please check your values';

} else {
if(attemptRegistration($_POST['memberID'],
$_POST['password'], $_POST['emailAddress'],
$_POST['givenName'], $_POST['surname'],
$_POST['gender'], $_POST['institution'],
$_POST['idNumber'], $_POST['major']) == false) {

generateError(1, 4, 'Registration Failed');
}
}
} else {

$register = @file_get_contents('templates/
dialogueBoxes.register.html' .
'dialogueBoxes.register.html');

echo $register;
}
break;
case 'retrieveaccount':

// Check if the link is from
// retrieveaccount.html. If not,
// show retrieveaccount.html. Else,
// process the form in the said html.
// User shall give his email address.
// If the email address is in the
// database, create another verification
// code. At the first login, user shall
// be referred to member.php?service=login.

if(!isset($_POST['submit'])) {

$retrieveaccount = @file_get_contents('templates/
retrieveaccount.html' . 'retrieveaccount.html') or
generateError(2, 1, 'Reading of the template file
has failed');

echo $retrieveaccount;

} else {

$emailAddress = $_POST['emailAddress'];

$emailAddressQuery = @mysql_query('SELECT * FROM jsp_users
WHERE emailAddress = "' . $emailAddress . '"');

if(mysql_query_rows($emailAddressQuery) == 0) {

return 'Email address is not in the database.';

} else {

$verificationCode = generateUniqueID(SHA1, false);

$insertTagQuery = @mysql_query('INSERT INTO
jsp_users (tag) WHERE emailAddress = "' .
$emailAddress . '" VALUES ("' .
$verificationCode . '")') or generateError(1, 4);

if($insertTagQuery) {

echo 'Your verification code is ' .
$verificationCode . '. Enter this code on your
first log in. Go to the login page!';
}
}
}
break;
case 'update':

// Check if the link is from update.html.
// If it is, check if user is logged in.
// If he is, check form values, and update account.
// If account update is successful,
// echo message to the user, or generateError.
// If the user is not logged in, tell him he is
// not logged in and show link to login.html.
// If the link is not from update.html, show
// update.html.

if(!isset($POST['submit'])) {

$update = @file_get_contents('templates/update.html' .
'update.html') or generateError(2, 1, 'Reading of
the template file has failed');
} else {

if(isLoggedIn() == true) {

if(validateInput() == false) {

echo 'Check values.';

} else {

if(updateProfile($_POST['memberID'],
$_POST['password'], $_POST['emailAddress'],
$_POST['givenName'], $_POST['surname'],
$_POST['gender'], $_POST['institution'],
$_POST['idNumber'], $_POST['major']) == false) {

return 'Update profile unsuccessful.';
}
}
} else {

return 'You are not logged in. Login!';
}
}
break;
default:
$index = @file_get_contents('
templates/index.html' .
'index.html') or generateError(2, 1,
'Reading of the template file has failed');
break;
}



?>

ronniethedodger
12-23-2003, 02:55 PM
What is the extension on this file (ie: is it .html)?

Do you have any files that need to have access permissions set to write in order for this to work?

Hard to say by just looking at the code itself. It might help if you have an active link to the page itself that you could post.

redcircle
12-23-2003, 07:14 PM
I am currently implementing an object-oriented programming in PHP. The files are compiling (not really compiling, what's a better word for this?)

The correct term is parse.


In order for PHP to parse you must have the .php extension or have the webserver set to parse .html files.


Are you getting any error codes?

trinski
12-25-2003, 04:43 AM
The code above is in .php extension.

It doesn't get parse errors but it doesn't work with html. I ran a simple test file of the functions and it works. It adds name to the database, etc. I can't work the files with the true or false implementation.

Saw a new bug. My @file_get_content syntax is wrong.
Now I get FATAL ERROR: Query execution has failed. It has something to do with mySQL syntax when I add something on the database. Hm.

trinski
12-25-2003, 04:47 AM
By the way, the code above is member.php.

And I am just working on IIS here at home, I haven't uploaded this at my webserver since it's being set up at the moment.

redcircle
12-25-2003, 01:34 PM
here is some beautified code www.phpedit.com download code beautifier.


<?php

set_magic_quotes_runtime(0);
ignore_user_abort(false);

require_once('registerFunctions.php');
require_once('errorFunctions.php');
require_once('commonFunctions.php');
require_once('userManager.php');
// require_once('languageDetector.php');
if (!isset($_GET['service']))
{
$_GET['service'] = '';
}

switch ($_GET['service'])
{
case 'login':
// Is the login from the login dialogue box?
// If it is, check entered values,
// get userID, check if member is verified,
// log in user, see member's permissions;
// else, return to index.html. [!!!]
if (!isset($_POST['submit']))
{
$index = @file_get_contents('templates/dialogueBoxes.login.html' . 'dialogueBoxes.login.html');

echo $index;
}
else
{
if (validateInput() == false)
{
echo 'Please check your values.';
}
if (loginUser() == false)
{
generateError(0, 0, 'Login failed.');
}
if ($status = loginUser($memberID, $password,
$verificationCode))
{
switch ($status)
{
case 0:
// If tagContentID is 1
// and tag has verification code.
return ('Login successful! Login!');
break;
case 1:
// If tagContentID is 0 and tag
// has verification code.
return ('Need your vericode. Enter it here.');
break;
case 2:
// If tagContentID is 0 and
// tag is not equal to code.
return ('Check your verification code again');
break;
case 3:
// If tagContentID is 0 and tag
// is equal to code.
return ('User verified. Login!');
}
}
if (isLoggedIn() == false)
{
generateError(0, 0, 'Unable to log in.');
}
else
{
$index = @file_get_contents('templates/dialogueBoxes.login.html' . 'dialogueBoxes.login.html');

echo $index;
}
}
break;
case 'register':
// Is the link member.php?service=register
// from register.html?
// If not, show register.html;
// else, check if user is registered.
// Did the user click on the button?
// if not, return to register.html;
// else, check if registration was
// successful and if inputs were
// valid.
if (isset($_POST['submit']))
{
if (validateInput() == false)
{
echo 'Please check your values';
}
else
{
if (attemptRegistration($_POST['memberID'],
$_POST['password'], $_POST['emailAddress'],
$_POST['givenName'], $_POST['surname'],
$_POST['gender'], $_POST['institution'],
$_POST['idNumber'], $_POST['major']) == false)
{
generateError(1, 4, 'Registration Failed');
}
}
}
else
{
$register = @file_get_contents('templates/dialogueBoxes.register.html' . 'dialogueBoxes.register.html');

echo $register;
}
break;
case 'retrieveaccount':
// Check if the link is from
// retrieveaccount.html. If not,
// show retrieveaccount.html. Else,
// process the form in the said html.
// User shall give his email address.
// If the email address is in the
// database, create another verification
// code. At the first login, user shall
// be referred to member.php?service=login.
if (!isset($_POST['submit']))
{
$retrieveaccount = @file_get_contents('templates/retrieveaccount.html' . 'retrieveaccount.html') or
generateError(2, 1, 'Reading of the template file has failed');

echo $retrieveaccount;
}
else
{
$emailAddress = $_POST['emailAddress'];

$emailAddressQuery = @mysql_query('SELECT * FROM jsp_users WHERE emailAddress = "' . $emailAddress . '"');

if (mysql_query_rows($emailAddressQuery) == 0)
{
return 'Email address is not in the database.';
}
else
{
$verificationCode = generateUniqueID(SHA1, false);

$insertTagQuery = @mysql_query('INSERT INTO jsp_users (tag) WHERE emailAddress = "' . $emailAddress . '" VALUES ("' . $verificationCode . '")') or generateError(1, 4);

if ($insertTagQuery)
{
echo 'Your verification code is ' . $verificationCode . '. Enter this code on your first log in. Go to the login page!';
}
}
}
break;
case 'update':
// Check if the link is from update.html.
// If it is, check if user is logged in.
// If he is, check form values, and update account.
// If account update is successful,
// echo message to the user, or generateError.
// If the user is not logged in, tell him he is
// not logged in and show link to login.html.
// If the link is not from update.html, show
// update.html.
if (!isset($POST['submit']))
{
$update = @file_get_contents('templates/update.html' . 'update.html') or generateError(2, 1, 'Reading of the template file has failed');
}
else
{
if (isLoggedIn() == true)
{
if (validateInput() == false)
{
echo 'Check values.';
}
else
{
if (updateProfile($_POST['memberID'],
$_POST['password'], $_POST['emailAddress'],
$_POST['givenName'], $_POST['surname'],
$_POST['gender'], $_POST['institution'],
$_POST['idNumber'], $_POST['major']) == false)
{
return 'Update profile unsuccessful.';
}
}
}
else
{
return 'You are not logged in. Login!';
}
}
break;
default:
$index = @file_get_contents('templates/index.html' . 'index.html') or generateError(2, 1,
'Reading of the template file has failed');
break;
}

?>



$insertTagQuery = @mysql_query('INSERT INTO jsp_users (tag) WHERE emailAddress = "' . $emailAddress . '" VALUES ("' . $verificationCode . '")') or generateError(1, 4);

You can't have a where clause in an insert tag.

it should be


$insertTagQuery = @mysql_query('INSERT INTO jsp_users (emailAddress, verifivationCode) VALUES ("'.$emailAddress.'","' . $verificationCode . '")') or generateError(1, 4);

trinski
12-26-2003, 02:07 AM
Or I could say update, since the user should be retrieving his account, since he forgot his password. New thing learned today. Thanks! :)