Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.