Jump to content

how come my post method search box works only once?


monger

Recommended Posts

//here is the code. For some reason it searches the first time, but the second search loads everything.

testing at: mnmotorsports.com

 

// searcha.php

 

<?php require("head.php");?>

<table width="800" border="1"><tr><td width="550"></td><td>

        <form  method="post" action="searcha.php?go"  id="searchform">

            <input  type="text" name="name">

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

        </form>

    </td></tr>

    <tr><td height ="300">

<?php

echo "searching";

    // connect to host

    require("connect.php");

 

    // retrieve data

    $name = $_POST['name'];

    echo " any card name matching: <b>'".$name."'</b>";

    $query = "SELECT * FROM ".$tname." WHERE name LIKE '%".$name."%'";

    $result = mysql_query($query) or die(mysql_error());

    $SearchCntr=0;

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

        $SearchCntr++;

        echo "<table border='1' width='500'>";

        echo "<tr><td>".$row['edition']." | <a href='#'>".$row['name']."</a> | ".$row['manacost']." | ".$row['price']."</td></tr>";

        echo "</table>";

    }

    echo $SearchCntr." SEARCH RESULTS</body></html>";

?>

 

            </td><td></td>

    </tr>

</table>

 

<?php require("footer.php"); ?>

Link to comment
Share on other sites

------ index.php -------

<?php require("head.php");?>

<table width="800" border="1"><tr><td width="550"></td><td>

            <form  method="post" action="<?PHP POST_SELF; ?>"  id="searchcards">

        <input  type="text" name="name">

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

    </form>

    </td></tr>

    <tr><td height ="300"><?php require("search.php"); ?></td><td></td>

    </tr>

</table>

<?php require("footer.php"); ?>

-------- search.php ----------

<?php

if ($_POST['submit']=="search"){

    // connect to host

    require("connect.php");

    // retrieve data

    $name = $_POST['name'];

    echo "Searching any card name matching: <b>'".$name."'</b>";

    $query = "SELECT * FROM ".$tname." WHERE name LIKE '%".$name."%'";

    $result = mysql_query($query) or die(mysql_error());

    $SearchCntr=0;

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

        $SearchCntr++;

        echo "<table border='1' width='500'>";

        echo "<tr><td>".$row['edition']." | <a href='#'>".$row['name']."</a> | ".$row['manacost']." | ".$row['price']."</td></tr>";

        echo "</table>";

    }

    echo $SearchCntr." SEARCH RESULTS</body></html>";

}else{

    echo "Search failed";

}

?>

Link to comment
Share on other sites

how come my post method text search box works only once?

-testing at mnmotorsports.com/searchtest2.php

--------------- simple version ------------------

<form  method="post" action="<?PHP POST_SELF; ?>"  id="searchcards">

        <input  type="text" name="name">

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

</form>

<?php

    // connect to host

    require("connect.php");

    // retrieve data

    $name = $_POST['name'];

    echo "Names matching: <b>'".$name."'</b>";

    $query = "SELECT * FROM ".$tablename." WHERE name LIKE '%$name%' ORDER BY name ASC";

    $result = mysql_query($query) or die(mysql_error());

    $SearchCntr=0;

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

        $SearchCntr++;

        echo "<table border='1'><tr><td><a href='#'>".$row['name']."</td></tr></table>";

    }

    echo $SearchCntr." SEARCH RESULTS";

?>

:confused:

Link to comment
Share on other sites

yeah, i just started scripting php about 4 days ago. I don't normally script in php.

 

The idea is to create an input text box. (that looks for %letters% in one row of info from the database)

 

It works, but not seamlessly. Somewhere there seems to be an error in the script and it works only once.

 

It's supposed to work over and over.

 

:shrug:

Link to comment
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.