Transferring data between php files

I am creating a web-based search application on a MYSYQL database with PHP. The application has three basic components:

  1. A SEARCH FORM (advanced_search.php) with several options – I have made good progress on this component and it appears to be working just fine. The form data is being collected and posted to the search results in step 2.

  2. A SEARCH RESULTS file (search_results.php) where basic document data is revealed in a list. The item in each row is a unique document identifier filtered on the search form in step 1 and linked to the full document in step 3. The data is being displayed ok as a link in each row and I can click the link and pull up the next step.

  3. A DOCUMENT TEXT (sectiontext.php) file with the associated full document text. The page loads from the link in the Search Results list, but there is no text data displayed. If I hard code a FullDocumentID into the query, it does pull up the correct document text for that ID. So I assume that it should work if I can just get the appropriate FullDocumentID transferred from step 2.

I have tried using both Get and Post to transfer the data, but seem to be having a problem. Here is the code I am currently using on the Search Results page which I think is relying on the Get method:

$result1 = mysql_query(“SELECT …”);
for ($a=0; $a < mysql_num_rows($result1); $a++)
{
$SQL_Array=mysql_fetch_array($result1);
$full_doc_number=$SQL_Array[‘full_doc_number’];
$FullDocumentID=$SQL_Array[‘FullDocumentID’];
echo “<a href=\ecr/sectiontext.php?ID=FullDocumentID”>$full_doc_number
";
}

This displays the data correctly as a list on the search_results page with links that pull up the sectiontext.php page, but no document text is displayed (empty table, no errors). It does not seem to be displaying the FullDocumentID number in the URL for the sectiontext.php in the browser. For example:

http://www… /sectiontext.php?ID=FullDocumentID"

There is no number for the FullDocumentID. I think this may be the problem, but since I am new to PHP, I could be missing something obvious.

I have also tried to Post the data between the pages with this code on both the search_results.php and sectiontext.php pages with no luck:

$FullDocumentID=$_POST[‘FullDocumentID’];

Any help getting this solved is appreciated. - Dave

Can you post your full Select statement?

You should ditch the for statement and just do it this way.

[php]$result1 = mysql_query(“SELECT …”);
while ($row = mysql_fetch_array($result1, MYSQL_ASSOC)) {
$full_doc_number=$row [‘full_doc_number’];
$FullDocumentID=$row [‘FullDocumentID’];
echo ‘’ . $full_doc_number . ‘
’;
}[/php]

Thanks for your prompt and helpful reply. I used your suggested code and now the URL for the sectiontext.php file is showing up properly in the browser, but I don’t get a document loaded in the table. As you requested, here is the original Select statement (search_results.php):

$result1 = mysql_query(
“SELECT
SectionText,
FullDocumentID,
ReadingNo,
SectionTypeID,
CONCAT(ReadingNo, ‘-’, SequenceNo) AS full_doc_number
FROM Full_Documents
WHERE SectionText LIKE ‘%$search_term%’ AND SectionTypeID = ‘$doctype’
Order By FullDocumentID”);

Here is my code for the sectiontext.php file where the full document text is supposed to be displayed. Again, no error message, simply no data in the table:

$result1 = mysql_query(
“SELECT
SectionText,
FullDocumentID
FROM Full_Documents
WHERE FullDocumentID = @FullDocumentID”);

echo "

";

while($row = mysql_fetch_array($result1))
{
echo “<tr class=“style2”>”;
echo “<td style=“width: 800px;”>” . $row[‘SectionText’] . “”;
echo “

”;
}
echo “
Text
”;
?>

Do I need to include something to recognize the FullDocumentID that shows up in the browser URL? (a Get statement?) Or does that happen automatically? Is $FullDocumentID the proper variable for the WHERE clause in the final call to the db? Thanks again for your help with this.

I have a feeling you’re just showing me pieces…

But if you make this change below it should work. I’m not saying this is the right way to do it, but it should get your your desired results.

[php]$result1 = mysql_query(
"SELECT
SectionText,
FullDocumentID
FROM Full_Documents
WHERE FullDocumentID = " . $_GET[‘ID’]);[/php]

You’re using obsolete code and you should convert everything to PDO…

Kevin, posted some quick start code for everyone to use here:

http://www.phphelp.com/forum/the-occasional-tutorial/beginners-pdo-bumpstart-code-use-it-now!

Yes, that solved my immediate problem very nicely. Thanks.

I will look into PDO. I do tend to rely a lot on web searches and find all kinds of things, some of it pretty dated, so thanks for that tip as well. - Dave

Sponsor our Newsletter | Privacy Policy | Terms of Service