Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Jun 2006
    Posts
    37
    Thanks
    0
    Thanked 0 Times in 0 Posts

    auto fill form using mysql data

    hi all,

    there's quite a lot threads about auto fill form, whether using PHP or not, but i cant find one method that suits me.

    i have a form for the user to input a book info, such as ISBN, book name, author, and these info will insert into mysql table after submit.

    what i'd like to do is when user fill the ISBN field, automatically fill the rest fields if this book info is already stored in the database.

    how can i do this?

    thanks a lot!

  • #2
    Regular Coder
    Join Date
    May 2005
    Posts
    235
    Thanks
    0
    Thanked 0 Times in 0 Posts
    It would probably be better to break the whole thing into two stages.
    firstly to enter the isbn number then submit it.
    If it is found on the data base the relevant details can be pulled out and echoed into the form.
    There is no way (afaik) php can 'autocomplete' a field without first getting all the information from the database... which is not practical because thats potentially a lot of information to hold in variables.

    Crowds
    PHP magpie | And President Of The Marmalade Atkins Fan Club | Crowds Design

  • #3
    New Coder
    Join Date
    Jun 2006
    Posts
    37
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thanks Crowds for your reply!

    i had thought to place a "autofill" button alongside the isbn input field, to query the database when clicked, then echo back data if any, but im not quite sure how to make it work with my current form.
    PHP Code:
    <form name="upload" method="post" action="process.php">
    <div>
    <label for="ISBN">ISBN</label>
    <input type="text" name="ISBN" class="input" size="20"  maxlength=15 value="<? echo $form->value("ISBN"); ?>">
    </div>
    <div>
    <label for="title">Title</label>
    <input type="text" name="title" class="input" size="30" maxlength=100 value="<? echo $form->value("title"); ?>">
    </div>
    <div>
    <label for="author">Author</label>
    <input type="text" name="author" class="input" size="37" maxlength=100 value="<? echo $form->value("author"); ?>">
    </div>
    the value echoed here is to retain after validation, how do i echo again for the auto fill?

  • #4
    Senior Coder Len Whistler's Avatar
    Join Date
    Jul 2002
    Location
    Vancouver, BC Canada
    Posts
    1,323
    Thanks
    26
    Thanked 100 Times in 100 Posts
    Quote Originally Posted by abanana
    how do i echo again for the auto fill?
    Try using sessions, this would be in the process.php

    PHP Code:
    <?php
    session_start
    ();
    $_SESSION['author'] = $_POST['author'];
    $_SESSION['ISBN'] = $_POST['ISBN'];

    ?>
    Leonard Whistler

  • #5
    New to the CF scene
    Join Date
    Jul 2006
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    extending the smarty class

    hi ive started working on an ecommerce site
    im using a smarty and pear which ive never used before
    ive only started and have come up with the following error message i would like if someone would have a look at it as im following a book and have copied the code not sure what the problem is !


    Parse error: syntax error, unexpected T_STRING, expecting T_FUNCTION in c:\wamp\www\passport\include\setup_smarty.php on line 10

    <?php
    //reference smarty libary
    require_once SMARTY_DIR.'Smarty.class.php';
    //reference our configuration file
    require_once 'config.inc.php';
    //class that extends Smarty,used to process and display Smarty files
    class Page extends Smarty
    {
    //constructor
    function_construct()
    {
    //call Smarty's constructor
    $this->Smarty();
    //change the default template directories
    $this->template_dir=TEMPLATE_DIR;
    $this->compile_dir=COMPILE_DIR;
    $this->config_dir=CONFIG_DIR;
    }
    }
    ?>

  • #6
    Regular Coder
    Join Date
    May 2005
    Posts
    235
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Wrap everything in php with the php tags please...
    Then it will look like this
    PHP Code:
    <?php
    //reference smarty libary
    require_once SMARTY_DIR.'Smarty.class.php';
    //reference our configuration file
    require_once 'config.inc.php';
    //class that extends Smarty,used to process and display Smarty files
    class Page extends Smarty
    {
    //constructor
    function_construct()
    {
    //call Smarty's constructor
    $this->Smarty();
    //change the default template directories
    $this->template_dir=TEMPLATE_DIR;
    $this->compile_dir=COMPILE_DIR;
    $this->config_dir=CONFIG_DIR;
    }
    }
    ?>
    And we can see what is going on better.

    Try this

    PHP Code:
    <?php
    //reference smarty libary
    require_once SMARTY_DIR.'Smarty.class.php';
    //reference our configuration file
    require_once 'config.inc.php';
    //class that extends Smarty,used to process and display Smarty files
    class Page extends Smarty
    {
    //constructor
    function_construct()
    {
    //call Smarty's constructor
    $this->Smarty();
    //change the default template directories
    $this->template_dir=TEMPLATE_DIR;
    $this->compile_dir=COMPILE_DIR;
    $this->config_dir=CONFIG_DIR;
    }
    ?>
    PHP magpie | And President Of The Marmalade Atkins Fan Club | Crowds Design


  •  

    Posting Permissions

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