The MU forums have moved to WordPress.org

How to add php to a wpmu page??? (6 posts)

  1. Realfam
    Member
    Posted 15 years ago #

    I have a php mySQL database search, etc and I want it to work in a wordpress page I will create called "Search". How can I put PHP into a wordpress page?

  2. andrea_r
    Moderator
    Posted 15 years ago #

    Create a custom page template for it.

  3. Realfam
    Member
    Posted 15 years ago #

    Yeah I am a novice, I do not know how to do that. I was hoping for a simple solution. Anything like that you know of?

  4. timmy77
    Member
    Posted 15 years ago #

  5. Realfam
    Member
    Posted 15 years ago #

    ok, I did it. Here is the issue. My script works perfectly as its own page, but when I put it into the template and hit search...the index.php comes up instead of the search results. Any ideas?

    Here is the code:

    <?php
    /*
    Template Name: Browse ExBriefs
    */
    ?>

    <?php get_header(); ?>

    <div id="content" class="narrowcolumn">

    <h2>Search</h2>
    <form name="search" method="post" action="<?=$PHP_SELF?>">
    Seach for: <input type="text" name="find" /> in
    <Select NAME="field">
    <Option VALUE="first">First Name</option>
    <Option VALUE="last">Last Name</option>
    <Option VALUE="city">City</option>
    <Option VALUE="state">State</option>
    <Option VALUE="country">Country</option>
    <Option VALUE="gender">Gender</option>

    </Select>
    <input type="hidden" name="searching" value="yes" />
    <input type="submit" name="search" value="Search" />
    </form>

    <?PHP
    //This is only displayed if they have submitted the form
    if ($_POST[searching] =="yes")
    {
    echo "<h2>Results</h2><p>";

    //If they did not enter a search term we give them an error
    if ($_POST[find] == "")
    {
    echo "<p>You forgot to enter a search term";
    exit;
    }

    // Otherwise we connect to our Database
    include("dbinfo.inc.php");
    mysql_connect(localhost,$username,$password);
    @mysql_select_db($database) or die( "Unable to select database");

    // We preform a bit of filtering
    $find = strtoupper($_POST[find]);
    $find = strip_tags($find);
    $find = trim ($find);

    //Now we search for our search term, in the field the user specified

    $data=mysql_query("select * from contacts where ".$_POST[field]." like '%".addslashes($find)."%'");

    //And we display the results
    while($result = mysql_fetch_array( $data ))
    {
    echo $result['first'];
    echo " ";
    echo $result['last'];
    echo "
    ";
    echo $result['city'];
    echo "
    ";
    echo $result['state'];
    echo "
    ";
    echo $result['country'];
    echo "
    ";
    echo $result['gender'];
    echo "
    ";
    echo "
    ";
    }

    //This counts the number or results - and if there wasn't any it gives them a little message explaining that
    $anymatches=mysql_num_rows($data);
    if ($anymatches == 0)
    {
    echo "Sorry, there is no Ex-Brief for <b>\"$find\"</b> yet
    Please try again.

    ";
    }

    }

    ?>

    </div>

    <?php get_sidebar(); ?>

    <?php get_footer(); ?>

  6. ex-brief
    Member
    Posted 15 years ago #

    I decided to just split up the html and php into seperate templates.......worked like a charm. thanks.

About this Topic

  • Started 15 years ago by Realfam
  • Latest reply from ex-brief