Jump to content

Recommended Posts

So the search function here was NO help...

 

I run a magazine and we want to move away from the database software we use and build our own. I am almost done but I ran into one road block:

 

We use Wordpress as the template for our website although it isn't all blog, we use many of the static pages. Anyhow, I have a search page that allows you to search the database but I cannot put the SELECT statement right on that page, it has to be in a separate file. So I take the search form and pass that data to a SELECT statement on the next page with POST method, but how do I then pass the results on to a third page where I can display them? Because we use templates, the scripts have to live at the root and data needs passed to the correct template file. So...

 

Page 1 (search) --> Page 2 (script, no page) --> page 3 (results, html display)

 

How do I pass data from a script to another page w/o a form showing up to the user?

 

 

Link to comment
https://forums.phpfreaks.com/topic/47703-help-with-post-method/
Share on other sites

I guess not. Here is what I have: How do I pass $cm_firstname and $cm_status to cm_display_subscriber.php?

 

[pre]<?php

 

// Makes initial conection to database

define ('DB_USER', '****');

define ('DB_PASSWORD', '****');

define ('DB_HOST', '****');

define ('DB_NAME', '****);

 

$connect = @mysql_connect(DB_HOST, DB_USER, DB_PASSWORD)

  or die('Our database is currently down for updates, please check back later.');

 

$db = @mysql_select_db(DB_NAME, $connect)

or die('Our database is currently down for updates, please check back later.');

 

// Aquires data source from form

$cm_search = $_POST['cm_search'];

 

 

// Selects data from the database

$findsubscriber = "(SELECT cm_firstname, cm_status FROM subscriber_data WHERE cm_firstname = '$cm_search')";

   

  $findsubscriber_result= mysql_query($findsubscriber)

  OR die('QUERY ERROR:<br />' .$buy. '<br />' .mysql_error()); 

 

while ($row = mysql_fetch_array($findsubscriber_result)) {

$cm_firstname = $row["cm_firstname"];

$cm_status = $row["cm_status"];

}

 

header("Location: cm_displaysubscriber.php");

 

exit;

?>

[/pre]

Link to comment
https://forums.phpfreaks.com/topic/47703-help-with-post-method/#findComment-233658
Share on other sites

That works (sorta) - is there no way to submit them via the POST or RESPONSE methods w/o showing them in the URL? Only reason is this is a subscriber database meant to be accessible from on the road and we don't want to leave people's names and addresses in the URL cache. But if I were to use this, I run into a problem.

 

When I push the data out to a blank white page, it shows up correctly with the GET method. However when I put it into my page template, it only shows the second variable value. Here is my code:

 

HTML Form

[pre]

html code

 

<form action="cm_findsubscriber.php" method="post" name="cm_subsearch">

<input type="text" size="20" name="cm_subsearchterm">

<br/>

<input type="submit" value="submit" name="cm_subsearchbutton">

</form>

 

html code

[/pre]

 

Which is passed to a search script

[pre]

<?php

 

// Makes initial connection to database

define ('DB_USER', '*****');

define ('DB_PASSWORD', '*****');

define ('DB_HOST', '*****');

define ('DB_NAME', '*****');

 

$connect = @mysql_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME)

  or die('Our database is currently down for updates, please check back later.');

 

$db = @mysql_select_db(DB_NAME, $connect)

or die('Our database is currently down for updates, please check back later.');

 

// Aquires data source from form

$cm_subsearchterm = $_POST['cm_subsearchterm'];

 

// Selects data from the database

$findsubscriber = "(SELECT cm_firstname, cm_status FROM subscriber_data WHERE cm_firstname = '$cm_subsearchterm')";

   

  $findsubscriber_result= mysql_query($findsubscriber)

  OR die('QUERY ERROR:<br />' .$buy. '<br />' .mysql_error()); 

 

while ($row = mysql_fetch_array($findsubscriber_result)) {

$cm_firstname = $row["cm_firstname"];

$cm_status = $row["cm_status"];

}

header("Location: http://www.mydomain.com/wordpress/?page_id=50?firstname=$cm_firstname&status=$cm_status");

exit;

?>

[/pre]

 

Which passes it back to the display page

[pre]

<?php

/*

Template Name: _subsdb_displayresults

*/

?> 

 

<?php get_header(); ?>

<div class="main_right">

    <?php include (TEMPLATEPATH.'/cs_right.php') ?>

</div>

  <?php include (TEMPLATEPATH.'/_subsdb_sidebar.php') ?>

<div class="main">

  <div class="formpadded">

<table width="480" height="200" bgcolor="#dcdcdc" cellpadding="0" cellspacing="0" align="left"  valign="bottom"  border="0">

  <tr>

    <td colspan="4">

      <table width="448" cellpadding="0" cellspacing="0" align="left"  valign="top"  border="0">

        <tr>

          <td width="20" bgcolor="#dcdcdc"></td>

          <td width="240" bgcolor="#dcdcdc">

            <?php echo $_GET["firstname"]; ?><br />

    <?php echo $_GET["status"]; ?><br />

            whiskey

          </td>

          <td width="188" bgcolor="#dcdcdc">

           

          </td>

        </tr>

      </table>

    </td>

  </tr>

  <tr height="10">

    <td colspan="4" height="60" bgcolor="#dcdcdc"> </td>

  </tr>

</table>

 

</form>

</div>

</div>

<div class="clearer"><span></span></div>

    <?php get_footer(); ?>

</div>

    </body>

    </html>

[/pre]

 

and the result is:

 

Active

whiskey

 

Where 'Active' is the status of the name I searched and whiskey is the text I added as a marker.

 

Where's the name value for $firstname? The value in the db is not null or empty, it shows up as 'Tim' when I push this to a blank page and not my template. I know it is a round about way of passing data but there is a reason behind my madness. I cannot connect to a databae directly from my blog, too many errors with mysql_close() and all that, so I keep the database code on script pages and the results on the template pages. Anyhow, is there a syntax error in passing my variables thru the URL, or in the delivery with the $_GET syntax?

 

Ideas?

Link to comment
https://forums.phpfreaks.com/topic/47703-help-with-post-method/#findComment-233781
Share on other sites

I have thought about that. This is a subscriber database that my customer service people will use hundreds of times per day. Either someone calls to subscribe to the magazine and they enter a new subscriber (that code is done) or search an existing subscriber for a renewal, address change or other reason. How would sessions effect multiple searches back to back, as far as ending one session and starting another w/o closing the browser? I guess kill all sessions when you go to the search page again, but then you have multiple people on the same IP too... sessions are started by each browser though, so that might work, I just don't want to store data in another database, how do you store data in a session w/o putting it in db fields?

Link to comment
https://forums.phpfreaks.com/topic/47703-help-with-post-method/#findComment-234107
Share on other sites

Consider reading up on session handling from the PHP manual, the following is a basic session handling extract:

 

Example 1860.  Registering a variable with $_SESSION.

<?php
session_start();
// Use $HTTP_SESSION_VARS with PHP 4.0.6 or less
if (!isset($_SESSION['count'])) {
   $_SESSION['count'] = 0;
} else {
   $_SESSION['count']++;
}
?>

Example 1861.  Unregistering a variable with $_SESSION and register_globals disabled.

 

<?php
session_start();
// Use $HTTP_SESSION_VARS with PHP 4.0.6 or less
unset($_SESSION['count']);
?>

Link to comment
https://forums.phpfreaks.com/topic/47703-help-with-post-method/#findComment-234349
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.