简体   繁体   中英

Using HTML to insert data into an SQL server table

A little background info: I am using Netbeans IDE 7.3, I have an SQL server running and I am trying to create a html application to insert data into the connected sql server /database structure.

I hope that made enough sense to see what I'm asking.

My question: I simply want to create a page on the HTML application which asks a user to enter information about a person such as their first name, last name, address, phone number, etc.

I want it to appear in this manner to the user:

First Name: [text area]

Last Name: [text area]

etc....

Then at bottom I want a submit button. At this point the information in the fields above would be sent to the "person" table in the database with each column/attribute filled with the appropriate information above.

A new row is created in the table at this point.

How can this be done? Examples of code would be great if you know of any.

Thanks in advance.

这不能单独使用 HTML 来完成,您需要像 PHP 这样的脚本语言来完成这项工作。

Build a form and use PHP to process it (or some other scripting language, I use PHP):

<form method="post" action="path_to_script.php">
    <label for="username">Username:</label>
    <input type="text" name="username" />
</form>

PHP:

    if(isset($_POST['username'])){
        $username = $_POST['username'];
    }

    // Use $username as a parameter in your query

$stmt = $yourDatabaseConnection->prepare("INSERT INTO yourTableHere (usernameColumn) VALUES (:username)");
$stmt->bindParam(':username', $username);

$stmt->execute();

Learn more about prepared statements here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM