addInput('name', 'text', 'Name', array('required' => true)); //adding input fields $form->addInput('email', 'email', 'Email', array('required' => true)); $form->addTextarea('message', 'Message', array('required' => true)); $form->addSubmit('Submit'); //submit button echo $form->display(); //displaying the form ?>
addInput('username', 'text', 'Username', array('required' => true)); $form->addInput('password', 'password', 'Password', array('required' => true)); $form->addInput('email', 'email', 'Email', array('required' => true)); $form->addSubmit('Register'); if(isset($_POST['submit'])) { $username = $_POST['username']; $password = $_POST['password']; $email = $_POST['email']; $stmt = $con->prepare("INSERT INTO users (username, password, email) VALUES (?, ?, ?)"); //using prepared statements to prevent SQL injection $stmt->bind_param("sss", $username, $password, $email); $stmt->execute(); } echo $form->display(); ?>This code creates a user registration form and inserts the submitted data into a MySQL database. The library provides easy integration with databases, and the use of prepared statements prevents SQL injection attacks.