Need professional help!

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
Cheeseboy
Forum Commoner
Posts: 67
Joined: Thu Mar 23, 2006 2:43 pm

Need professional help!

Post by Cheeseboy »

Hi, I have had this problem for many days on here: http://www.codingforums.com/showthread.php?t=82504 Now i need professional help so i came here. :D

Thx
matthijs
DevNet Master
Posts: 3360
Joined: Thu Oct 06, 2005 3:57 pm

Post by matthijs »

Did you set

Code: Select all

ini_set('error_reporting', E_ALL);
ini_set('display_errors', TRUE);
at the top of the script to spot any errors and also var_dump($var) everywere in between, so you can see what's happening?
User avatar
Cheeseboy
Forum Commoner
Posts: 67
Joined: Thu Mar 23, 2006 2:43 pm

Post by Cheeseboy »

nope it didnt show anyerrors is it ok to get rid of all the html tags? since tis a .php file?
matthijs
DevNet Master
Posts: 3360
Joined: Thu Oct 06, 2005 3:57 pm

Post by matthijs »

Which html tags?

As long as you seperate the html and php itis ok

Code: Select all

<?php
// this is php
$var = 'this';
?>
<h2>Normal html</h2>
About you script: what you can do to debug it is after each line of code var_dump the variables to see if they are empty or what they contain. That'll lead you to the source of the trouble fast.

Code: Select all

<?php
$name = $_POST['name'];
var_dump($name);

// etc
?>
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Your code should be throwing a header error at the very least since you are calling session_start() after you have outputted html to the browser. Try doing somthing like this and see what the source of the output is.

Code: Select all

<?php
session_start();
?>
<html>
<head>
<title>validate.php</title>
</head>
<body>
Ok, we are about to start: <?php echo date("m-d-Y g:i A"); ?>.
<?php
if (isset($_POST))
{
	$user_name = $_POST['user_name'];
	$password = $_POST['password'];
	$db_user = 'mysql_username';
	$db_pass = 'mysql_password';

	//connect to the DB and select the "dictator" database
	$connection = mysql_connect('localhost', $db_user, $db_pass) or die(mysql_error());
	mysql_select_db('Esgames4ulogin') or die(mysql_error());

	//set up the query
	$query = "SELECT * FROM users 
			WHERE user_name='$user_name' AND password='$password'";
	// Test output of something
	echo $query . "<br />\n";
		
	//run the query and get the number of affected rows
	$result = mysql_query($query, $connection) or die('error making query: ' mysql_error());

	//if there's exactly one result, the user is validated. Otherwise, he's invalid
	if(1 == mysql_num_rows($result)) {
		echo 'validated';
	}
	else {
		echo 'not valid';
	}
}
else
{
	echo 'There was nothing posted...';
}
?>
OK, finishing up: <?php echo date("m-d-Y g:i A"); ?>.
</body>
</html>
User avatar
Cheeseboy
Forum Commoner
Posts: 67
Joined: Thu Mar 23, 2006 2:43 pm

Post by Cheeseboy »

I still get a blank page. I dont think its in the code. well if you guys have a login script ill just use it and trash this one. I got it from a tutorial anyways.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

Copy and past the code above into a new file and run it. You might have an invalid character entity in your existing file from another wysiwyg editor or something and you would have a hard time fixing it. What editor are you using?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

by blank page, do you mean there's no source sent at all? .. or the isn't any output in the source?

Run the following in a new file and tell us the results please.

Code: Select all

<?php

$ve = phpversion();
$os = PHP_OS;
$er = intval(error_reporting());
$rg = (in_array(strtolower(ini_get('register_globals')), array(0, false, '', null, 'off')) ? 'Off' : 'On');
$de = (in_array(strtolower(ini_get('display_errors')), array(0, false, '', null, 'off')) ? 'Off' : 'On');
$so = (in_array(strtolower(ini_get('short_open_tag')), array(0, false, '', null, 'off')) ? 'Off' : 'On');
$eol = (isset($_SERVER['HTTP_HOST']) ? "<br />\n" : "\n");

$ec = array(
   'E_STRICT' => 2048,
   'E_ALL' => 2047,
   'E_USER_NOTICE' => 1024,
   'E_USER_WARNING' => 512,
   'E_USER_ERROR' => 256,
   'E_COMPILE_WARNING' => 128,
   'E_COMPILE_ERROR' => 64,
   'E_CORE_WARNING' => 32,
   'E_CORE_ERROR' => 16,
   'E_NOTICE' => 8,
   'E_PARSE' => 4,
   'E_WARNING' => 2,
   'E_ERROR' => 1,
);

$e = array();
$t = $er;
foreach ($ec as $n => $v)
{
   if (($t & $v) == $v)
   {
      $e[] = $n;
      $t ^= $v;
   }
}
$er = $er . ' (' . implode(' | ', $e) . ')';

echo 'PHP Version ' . $ve . $eol;
echo 'PHP OS ' . $os . $eol;
echo 'Error Reporting ' . $er . $eol;
echo 'Register Globals ' . $rg . $eol;
echo 'Short Tags ' . $so . $eol;
echo 'Display Errors ' . $de . $eol;

?>
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

OK, lets begin the troubleshooting...

1. Is your cache clear?
2. Is the file in the right directory?
3. Is the file being called by a form submission?
4. Will another .php file in the same directory parse as expected?

Lets start with these and see if there is anything we can get from this problem. What do you say?

EDIT: This post seems so out of place after Feyd's post. Oh well, it's been a while for me... you know, getting outposted by Feyd.

<imagining>Two geeks in cowboy hats starin' at each other. Draw... er, I mean Post!</imagining>
User avatar
Cheeseboy
Forum Commoner
Posts: 67
Joined: Thu Mar 23, 2006 2:43 pm

Post by Cheeseboy »

feyd heres your info i got.

Code: Select all

PHP Version 4.4.0
PHP OS Linux
Error Reporting 2047 (E_ALL)
Register Globals Off
Short Tags On
Display Errors Off

Im using kwrite by the way
User avatar
Cheeseboy
Forum Commoner
Posts: 67
Joined: Thu Mar 23, 2006 2:43 pm

Post by Cheeseboy »

ok Everah:
Im searching for this on the server so do i still nedd to clear the cache? 1. Is your cache clear?
Yes 2. Is the file in the right directory?
i dont know 3. Is the file being called by a form submission?
Do you mean will another php file work? if so yes others will. 4. Will another .php file in the same directory parse as expected?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

I'm going to guess that your server is Apache. If so, save this as ".htaccess" in the directory (make sure to notice the leading period), if one exists, edit this into it.

Code: Select all

php_flag display_errors on
after you get that squared away, try to run your script again.
User avatar
Cheeseboy
Forum Commoner
Posts: 67
Joined: Thu Mar 23, 2006 2:43 pm

Post by Cheeseboy »

ok, with the help of a friend i got the errors turned on and i get this in everah's code:

Code: Select all

Parse error: parse error, unexpected T_STRING in /var/www/Esgames4uweb/validate.php on line 31
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

Code: Select all

$result = mysql_query($query, $connection) or die('error making query: ' . mysql_error());
Add a . it may need a concator.
User avatar
Cheeseboy
Forum Commoner
Posts: 67
Joined: Thu Mar 23, 2006 2:43 pm

Post by Cheeseboy »

ok got this error now:

Code: Select all

Parse error: parse error, unexpected T_CONSTANT_ENCAPSED_STRING in /var/www/Esgames4uweb/validate.php on line 36
Post Reply