Hi Forum,

I'm currently working on a project where I create a form in Javascript/HTMl(easy). By form, i mean an actual form where it shall contain combo boxes, drop-down lists, buttons etc. Something like a questionnaire. That's all good and simple enough. However, how can I use this questionnaire/form to talk to a database. It needs to store information to a database. Whatever the user inputs, it needs to save that data to a database.

Any help is greatly appreciated.


You would need something to handle the data from your form. Your form should have an "action" attribute specified which defines where to send the data. I don't think you can send it back to the JavaScript form, because JavaScript has to be executed by the browser.

Therefore, you'll need another tool to handle the data. PHP is one of the easiest ways to handle form data and connect to a database, but there are many other ways -- ASP, Perl, Python, Ruby, C/C++, etc.

Here would be a simple form-handling script using PHP that takes in the data from a form's input boxes named "f_name", "l_name", and "email_addr" and submits the values of those to a table named "users" in a database named "mydb" on the local server:

function db_connect()
  $result = @mysql_pconnect("localhost", "root", "somepass");
  if (!$result)
    return false;
  if (!@mysql_select_db("mydb"))
    return false;
  return $result;
$conn = db_connect();
$sql = "insert into users (fname, lname, email) values ('$f_name', '$l_name', '$email_addr');
$result = mysql_query ($sql, $conn);
header("Location: http://localhost/thankyou.php");
Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.