hi all,
Can u teach me, how to create table for multi select checkbox on PHPMYADMIN?
i had problem with my database report and html/php, details as bellow:
1.) i create database as a “test_form” and create table as a “form”
2.) under “form” i create :
a.) id >int(20)>AI
b.)name>varchar(50)>latin1_swedish_ci
c.)access>set(hr,account,purchasing,)>latin1_swedish_ci
3.) i create connect.php code as below:
<
?php
$dsn = "mysql:dbname=test_form;host=localhost";
$user = "root";
$pass = "";
try {
$dbh = new PDO($dsn, $user, $pass);
} catch (PDOException $e) {
echo "cannot connect to database: ".$e->getMessage();
}
?>
4.) i create input.php code as below:
<form action="save.php" method="post">
<p>
Full Name
<input type="text" name="name" required />
<p>
<input type="checkbox" name="access" value="hr" id="hr">Human Resources - HR</label><br />
<input type="checkbox" name="access" value="account" id="account"><label for="account">Account</label><br />
<input type="checkbox" name="access" value="purchasing" id="purchasing"/><label for="purchasing">Purchasing</label>
<p>
<input type="submit" value="submit" onclick="return confirm('Are You Sure To submit this form?')"/>
</fieldset>
5.) and i create save.php code as bellow:
<?php
include'connect.php';
if (isset($_POST)) {
$sql = "INSERT INTO form VALUES ('', '$_POST[name]', '$_POST[access]' )";
$dbh->exec($sql);
}
header("location:index.php");
?>
6.) lastly i create index.php code as below:
<?php
include 'connect.php';
?>
<thead>
<tr>
<th>No</th>
<th>Name</th>
<th>Access</th>
</tr>
</thead>
<tbody>
<?php
$sql = "SELECT * FROM form ORDER BY id";
$no = 1;
foreach ($dbh->query($sql) as $data) :
?>
<tr>
<td><?php echo $no++; ?></td>
<td><?php echo $data['name'] ?></td>
<td><?php echo $data['access'] ?></td>
<td align="center">
</td>
</tr>
<?php
endforeach;
P/s: the problem is, when i select 2 checkbox or 3…only show 1 select on my PHPMYADMIN.
exm: i select “hr” and "account’ . only ‘account’ will show on my database also my index.php.
Help me and teach me,how to solve this issue…
Thanks.