37 users online (1 members and 36 guests)  


  Results 1 to 2 of 2

Related

  1. form input changes textarea output    Forum: Javascript Forum
    Replies: 1
  2. Replies: 6
  3. html form data output    Forum: HTML Forum
    Replies: 1
  4. PHP & MySQL search    Forum: PHP Forum
    Replies: 3
  1. #1
    basketmen's Avatar
    New User

    Status
    Offline
    Join Date
    Apr 2007
    Posts
    18

    Form output using mysql, search people name in specific category

    I have search php forms that connecting to mysql, for search people name in all category and search people name in specific category
    People name field in mysql : people_name , example : John, Michael, etc
    category name field in mysql : people_category , example : Kid, Adult, etc

    I can Search All People name using first option value below, for example i search : John
    beside that i want to search : John only in adult category
    what is the right code so i can get people name just from adult category

    <select name="metode" size="1">
    <option value="people_name">Search All People</option>
    <option value="people_name_just_from_adult_category">Search People By Category</option>
    </select>
    <input type="text" name="search" size="25">
    <input type="submit" value="Search" name="Go" />


    Please share your php mysql knowledge here

  2. #2
    Php_Jesse's Avatar
    New User

    Status
    Offline
    Join Date
    Apr 2008
    Posts
    4

    Re: Form output using mysql, search people name in specific category

    Well one way you could go about it is:


    SQL:
    Code:
    CREATE TABLE peoples
    (
    name int(11),
    age tinyint(1)
    )
    CODE:
    Code:
    <?php
    if(empty($_POST['name']))
    {
    echo <<<WTF
    <form action={$_SERVER["PHP_SELF"]} method=post>
    <input type=text name=name /><br />
    <select name=age size=1>
    <option value=0>Child</option>
    <option value=1>Adult</option>
    </select>
    <input type=submit value='Submit!' /></form>
    WTF;
    }
    else
    {
    $name=htmlspecialchars($_POST['name']);
    $age=abs($_POST['age']);
    $q=mysql_query("SELECT * FROM peoples WHERE name={$name} AND age={$age} LIMIT 1",$c);
    $ir=mysql_fetch_assoc($q);
    }
    ?>
    Names would be case sensitive, adult would have an age of 1, and child would have age of 0. Fairly simple though. Script probably has a bug as I wrote it on the fly but it should work after a minute of debugging.



Tags for this Thread