Jump to content

html checkbox to populate SQL table


georgehowell

Recommended Posts

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);  }

}

?>

Link to comment
https://forums.phpfreaks.com/topic/199475-html-checkbox-to-populate-sql-table/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.