...

View Full Version : auto fill form using mysql data



abanana
08-23-2006, 04:36 AM
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!

Crowds
08-23-2006, 05:24 AM
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

abanana
08-23-2006, 05:58 AM
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.

<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?

Len Whistler
08-23-2006, 07:06 AM
how do i echo again for the auto fill?

Try using sessions, this would be in the process.php


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

?>

magoo07
08-24-2006, 06:56 PM
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;
}
}
?>

Crowds
08-24-2006, 09:00 PM
Wrap everything in php with the php tags please...
Then it will look like this

<?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
//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;
}
?>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum