www.webdeveloper.com
Results 1 to 5 of 5

Thread: php function and form

  1. #1
    Join Date
    Oct 2004
    Posts
    22

    php function and form

    hi i was wondering where in my script there's an error.
    foobar.html
    Code:
    <html>
    <head>
    <title>
    </title>
    </head>
    <body>
    <form name="search" method="get" action="foobar.php?action=humbug">
    Search</br>------</br>
    <label for="title_search">Title</label></br>
    <input id="title_search" name="title_search" type="text"></br></br>
    <input type="submit" value="Search!">
    </form>
    </body>
    </html>
    foobar.php
    Code:
    <?php
    function humbug(){
    mysql_connect("","","") or die(mysql_error());
    mysql_select_db("") or die(mysql_error());
    $title_search=$_GET["title_search"];
    $result=mysql_query("SELECT * FROM ml WHERE title LIKE '%$title_search%'");
    while($rowresult=mysql_fetch_array($result)){
    echo "<tr><td class='title'>"; 
    echo $rowresult['title'];
    echo "</td><td class='year'>"; 
    echo $rowresult['year'];
    echo "</td><td class='view'>"; 
    echo $rowresult['1st'];}}
    ?>
    if i make the action to foobar.php AND write the php script not as a function it works. what am i doing wrong?

  2. #2
    Join Date
    Mar 2007
    Posts
    946
    Are you calling the function in your file?

  3. #3
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    18,923
    A function only gets processed when it is called. Simply calling a script that has a function definition in it will not fire off that function. (For that matter, if that is all the "foobar.php" script does, then there is no real reason to put it into a function.)

    If you have a reason to put the functionality in a function, then you would have to do something like:
    PHP Code:
    <?php
    function humbug()
    {
       
    // blah blah blah . . .
    }

    // invoke it:
    humbug();
    ?>
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  4. #4
    Join Date
    Oct 2004
    Posts
    22
    foobar.php is a file with many php functions.

    when i submit the form in foobar.html. i want to run a specific function known as function humbug() in foobar.php.

    how do i do that?

  5. #5
    Join Date
    Oct 2004
    Posts
    22

    Thumbs up

    thanks alot!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles