Search database/Page Results

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
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

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

Code: Select all

<?php

$neg = array('off', 0, false, '', null);
$flags = array(
	'Register Globals' => 'register_globals',
	'Short Tags' => 'short_open_tag',
	'Display Errors' => 'display_errors',
	'Magic Quotes GPC' => 'magic_quotes_gpc',
	'Magic Quotes Runtime' => 'magic_quotes_runtime',
	'Magic Quotes Sybase' => 'magic_quotes_sybase',
);
$ve = phpversion();
$os = PHP_OS;
$er = intval(error_reporting());
foreach ($flags as $n => $v)
{
	$flags[$n] = (in_array(strtolower(ini_get($v)), $neg) ? 'Off' : 'On');
}
$cli = (php_sapi_name() == 'cli');
$eol = "\n";

$gle = get_loaded_extensions();
$rows = array();
$le = '';
$wide = 4;
$j = count($gle);
$pad = $wide - $j % $wide;
$len = max(array_map('strlen', $gle));
$func = create_function('$a', 'return str_pad($a, ' . intval($len) . ');');
$gle = array_map($func, $gle);
for($i = 0; $i < $j; $i += $wide)
{
	$le .= '   ' . implode('   ', array_slice($gle, $i, $wide)) . $eol;
}

$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;
	}
}
if (ceil(count($ec) / 2) + 1 < count($e))
{
	$e2 = array();
	foreach ($ec as $n => $v)
	{
		if (!in_array($n, $e) and $n != 'E_ALL')
		{
			$e2[] = $n;
		}
	}
	$er = $er . ' ((E_ALL | E_STRICT) ^ ' . implode(' ^ ', $e2) . '))';
}
else
{
	$er = $er . ' (' . implode(' | ', $e) . ')';
}

if (!$cli)
{
	echo '<html><head><title>quick info</title></head><body><pre>', $eol;
}

echo 'PHP Version: ', $ve, $eol;
echo 'PHP OS: ', $os, $eol;
echo 'Error Reporting: ', $er, $eol;
foreach ($flags as $n => $v)
{
	echo $n, ': ', $v, $eol;
}
echo 'Loaded Extensions:', $eol, $le, $eol;

if (!$cli)
{
	echo '</pre></body></html>', $eol;
}

?>
sparky753
Forum Commoner
Posts: 51
Joined: Fri Nov 03, 2006 10:39 am

Post by sparky753 »

This is the result i get:

Code: Select all

PHP Version: 4.3.9
PHP OS: Linux
Error Reporting: 2047 (E_ALL)
Register Globals: On
Short Tags: On
Display Errors: On
Magic Quotes GPC: Off
Magic Quotes Runtime: Off
Magic Quotes Sybase: Off
Loaded Extensions:
   yp               xml              wddx             tokenizer     
   sysvshm          sysvsem          standard         sockets       
   shmop            session          pspell           posix         
   pcre             overload         mime_magic       iconv         
   gmp              gettext          ftp              exif          
   dio              dbx              dba              curl          
   ctype            calendar         bz2              bcmath        
   zlib             openssl          apache2handler   mysql
sparky753
Forum Commoner
Posts: 51
Joined: Fri Nov 03, 2006 10:39 am

Post by sparky753 »

Replying to Evrah's previous posting, why do you suppose it's not posting? Would you have any suggestions?

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

Post by RobertGonzalez »

That is the question. I am not really sure without seeing the entire process flow of the app. It might just be easier to start all over again.
sparky753
Forum Commoner
Posts: 51
Joined: Fri Nov 03, 2006 10:39 am

Post by sparky753 »

I now realize what's going on but i'm not sure how to fix it. The problem's not that the form is not posting data - the posted value 'LastName' is not getting assigned to the session variable

Code: Select all

$_SESSION['LastName'] = $_POST['LastName'];
would anyone have any ideas or suggestions? Thanks....
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Before this:

Code: Select all

$_SESSION['LastName'] = $_POST['LastName'];
do this

Code: Select all

echo '<h1>Last Name as posted is ' .  $_POST['LastName'] . '</h1>';
What does that output?
sparky753
Forum Commoner
Posts: 51
Joined: Fri Nov 03, 2006 10:39 am

Post by sparky753 »

You probably remember I have 2 pages - search4.php submits to search5.php. I put the line of code you typed to see if it's printing the posted last name - it's printing it correctly on search5.php...
sparky753
Forum Commoner
Posts: 51
Joined: Fri Nov 03, 2006 10:39 am

Post by sparky753 »

I might have an idea what's causing the problem. I noticed that my if statement in search4.php (that checks to see if the Submit button has been clicked) displays the else part of the code if the form has not been submitted but the if part doesn't do anything...i wonder if that is because the form is submitting to search5.php and so the if part isn't getting processed.

Code: Select all

<?php
                  if (isset($_POST['submit'])) {
                  print_r($_POST);
                  $_SESSION['LastName'] = $_POST['LastName'];
                  echo "Hello";
                  echo $_SESSION['LastName'];
                        }
                  else {
                   //do nothing
                  echo "Goodbye";
                   }
          ?>
When search4.php is first loaded (and the form isn't submitted), the else part is executed:

Code: Select all

Goodbye
But the moment i click submit, none of the statements in the if part are executed...that might explain why the posted value is not getting assigned to the session variable. How would i do that then? if i don't have an if statement the $_POST['LastName'] variable would give an error since the form isn't submitted when the page is loaded the first time...
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

How about we rename the pages. I am totally lost in the file system right now. Does page4.php ever have anything posted to it? Please explain what each page is supposed to do.
sparky753
Forum Commoner
Posts: 51
Joined: Fri Nov 03, 2006 10:39 am

Post by sparky753 »

I know..it probably wasn't the best naming convention but i was trying all permutations and combinations with my search pages, i got tired of naming them properly.

search4.php - the main Search page with the form. The form has a LastName text field, which is what we want to pass to the next page 'search5.php' (let's call it 'process.php').
process.php - this page uses the LastName value submitted from the search4.php page to perform queries against the database - the results are displayed on this page. A simple $_POST variable would suffice if 'process.php' was only getting loaded once but because i've got my search results appearing in multiple pages, the $_POST variable would generate an error when i click to view Page 2 or any other pages. This is because, when we go to any other page besides the first page, 'process.php' has no clue what the $_POST variable is. As a result, we decided to go with session variables.

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

Post by RobertGonzalez »

That clears it up. Page4 can be the 'form.php' page, page5 can be the 'results.php' page. Here's what you do... check to see if the form was processed from 'form.php' first. This will tell you if it is a fresh page load or not. If it is not set, then look for a session var that is set. If it is, then we are on a section of the search result that is not the first section. If the session is not set AND the post is not set, then someone is loading this page freshly and they should be redirected to the form.

results.php

Code: Select all

<?php
session_start();
if (isset($_POST['LastName'])) // Or any other required field
{
    // This is a posted form
    $_SESSION['LastName'] = $_POST['LastName']; // This should be validated of course
}
elseif (isset($_SESSION['LastName']))
{
    // We are on a section of the pages results
}
else
{
    // Neither the form or session is set, redirect them to the form
    header('Location: http://www.mysite.com/form.php');
    exit;
}
?>
sparky753
Forum Commoner
Posts: 51
Joined: Fri Nov 03, 2006 10:39 am

Post by sparky753 »

Fabulous!! It works!! It works!! Thanks so much!! I've been messing with this for over a week. You have no idea how ecstatic I am. If you're a guy, I'll give you a manly hug and if you're a woman, I'd give you a peck... Thanks a lot, Evrah. You have made my day!!
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

I'm a guy. No hugs needed. Pizza and Soda Image works for me, as does babysitting my kids so the wife and I can have some 'married persons' time Image ... oh wait, I meant Image ..., oh wait, I meant Image & Image.
sparky753
Forum Commoner
Posts: 51
Joined: Fri Nov 03, 2006 10:39 am

Post by sparky753 »

Ha! Ha! Ha! Thanks so much. I appreciate all your help on this...Have a great weekend with your wife and kids.
Post Reply