georgehowell Posted April 23, 2010 Share Posted April 23, 2010 dear PHP experts out there, I've been successful in populating a designated table in a MySQL database up until including a checkbox in the html form. Here's my code so far: "RegoForm.html" <form name="join" action="register.php" method="post"> NAME: <input name="name" type="text" > EMAIL: <input name="email" type="text" > NEWSLETTER: <input name="subscribe" type="checkbox" id="newsletter" value="true" property="boolean" > <input name="submit" type="submit" id="submit" > </form> "register.php" <?php include("lib/ConnectToDb.php"); include("lib/User.php"); print_r($_POST); if(isset($_POST['username']) && isset($_POST['password'])) { $user = new User(); if($user->register( $_POST['name'] $_POST['email'], $_POST['subscribe'])) { include("Welcome.php"); exit(); } } ?> "ConnectToDb.php" <?php class ConnectToDb { protected $db; public function __construct() { $this->connect(); } public function connect() { $database = "SkyZone"; $username = "root"; $password = ""; // connect to database $this->db = new PDO("mysql:host=localhost;dbname=$database",$username,$password); } } ?> "User.php" <?php class User extends ConnectToDb { public function __construct() { parent::__construct(); } public function login($username,$password) { $ps = $this->db->prepare("Select username, password from users where username = ? and password = ?"); $ps->execute(array($username,$password)); return ($ps->rowCount() == 1); } public function register($name,$email,$subscribe) { $ps = $this->db->prepare("Insert into users (name,email,subscribe) values (?,?,?)"); $ps->execute(array($name,$email,$subscribe)); return ($ps->rowCount() == 1); } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/199475-html-checkbox-to-populate-sql-table/ Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.