Commit eb63ec3d by wongsakorn

up to git

parents
PHP Version: 5.6.39
phpMyAdmin SQL Dump version 4.8.4
Server : localhost
Username : root
Password :
Database : test
<?php
require_once "database.php";
if($_SERVER["REQUEST_METHOD"] == "POST"){
$sql = "INSERT INTO users (name, lastname, gender, birth_date, mail, address, phone_number) VALUES (?, ?, ?, ?, ?, ?, ?)";
if($stmt = mysqli_prepare($link, $sql)){
mysqli_stmt_bind_param($stmt, "sssssss", $param_name, $param_lastname, $param_gender, $param_birth, $param_mail, $param_add, $param_phone);
$param_name = $_POST["name"];
$param_lastname = $_POST["lastname"];
$param_gender = $_POST["gender"];
$param_birth = $_POST["birth_date"];
$param_mail = $_POST["mail"];
$param_add = $_POST["address"];
$param_phone = $_POST["phone_number"];
if(mysqli_stmt_execute($stmt)){
header("location: index.php");
exit();
} else{
echo "เกิดข้อผิดพลาด กรุณาลองใหม่อีกครั้ง";
}
}
mysqli_stmt_close($stmt);
mysqli_close($link);
}
?>
<html lang="en">
<head>
<title>
Bootstrap Validation example using validator.js
</title>
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"
integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<script src="https://unpkg.com/gijgo@1.9.13/js/gijgo.min.js" type="text/javascript"></script>
<link href="https://unpkg.com/gijgo@1.9.13/css/gijgo.min.css" rel="stylesheet" type="text/css" />
<!-- <script src="https://cdnjs.cloudflare.com/ajax/libs/1000hz-bootstrap-validator/0.11.5/validator.min.js"></script> -->
</head>
<body>
<br />
<div class="container">
<div class="panel panel-primary" style="width:750px;margin:0px auto">
<div class="panel-heading">Add User</div>
<div class="panel-body">
<form data-toggle="validator" role="form" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>"
method="post">
<div class="form-group">
<label class="control-label">Name</label>
<input class="form-control" data-error="Please enter name field." name="name" placeholder="Name"
type="text" required />
<div class="help-block with-errors"></div>
</div>
<div class="form-group">
<label class="control-label">Last Name</label>
<input class="form-control" data-error="Please enter lastname field." placeholder="Email"
name="lastname" required>
<div class="help-block with-errors"></div>
</div>
<div class="form-group">
<label class="control-label">Gender</label>
<select id="inputState" class="form-control" data-error="Please enter gender field." name="gender"
required style="width:270px;">
<option value="">----Select----</option>
<option value="M">Man</option>
<option value="W">Woman</option>
</select>
<div class="help-block with-errors"></div>
</div>
<div class="form-group">
<label class="control-label">Birthdate</label>
<div class="form-group">
<input id="datepicker" name="birth_date" width="270" required/>
<div class="help-block with-errors"></div>
</div>
</div>
<div class="form-group">
<label class="control-label">E-mail</label>
<input class="form-control" data-error="Please enter birth date field." placeholder="E-mail"
name="mail" required>
<div class="help-block with-errors"></div>
</div>
<div class="form-group">
<label class="control-label">Address</label>
<textarea class="form-control" data-error="Please enter address field." placeholder="Address"
name="address" required=""></textarea>
<div class="help-block with-errors"></div>
</div>
<div class="form-group">
<label class="control-label">Phone Number</label>
<input class="form-control" data-error="Please enter birth date field." name="phone_number" maxlength="10"
onkeyup="phone_num_format()" id="phone_number" placeholder="Phone Number" required
style="width:270px;">
<div class="help-block with-errors"></div>
</div>
<div class="form-group">
<button class="btn btn-primary" type="submit">Submit</button>
</div>
</form>
</div>
</div>
</div>
</body>
</html>
<script>
$('#datepicker').datepicker({
uiLibrary: 'bootstrap',
format: 'yyyy-mm-dd'
});
function phone_num_format() {
var phone = $('#phone_number').val();
if (phone !== '') {
intRegex = /[0-9 -()+]+$/;
if ((phone.length > 10) || (!intRegex.test(phone))) {
alert('Please enter a valid phone number.');
$('#phone_number').val('');
return false;
}
}
}
</script>
\ No newline at end of file
<?php
/* Database credentials. Assuming you are running MySQL
server with default setting (user 'root' with no password) */
define('DB_SERVER', 'localhost');
define('DB_USERNAME', 'root');
define('DB_PASSWORD', '');
define('DB_NAME', 'test');
/* Attempt to connect to MySQL database */
$link = mysqli_connect(DB_SERVER, DB_USERNAME, DB_PASSWORD, DB_NAME);
// Check connection
if($link === false){
die("ERROR: Could not connect. " . mysqli_connect_error());
}
?>
\ No newline at end of file
<?php
if(isset($_GET["id"])){
require_once "database.php";
$sql = "DELETE FROM users WHERE id = ?";
if($stmt = mysqli_prepare($link, $sql)){
mysqli_stmt_bind_param($stmt, "i", $param_id);
$param_id = trim($_GET["id"]);
if(mysqli_stmt_execute($stmt)){
header("location: index.php");
exit();
} else{
echo "เกิดข้อผิดพลาด กรุณาลองใหม่อีกครั้ง";
}
}
mysqli_stmt_close($stmt);
mysqli_close($link);
} else{
if(empty(trim($_GET["id"]))){
header("location: error.php");
exit();
}
}
?>
\ No newline at end of file
<?php
require_once "database.php";
if(isset($_POST["id"]) && !empty($_POST["id"])){
$id = $_POST["id"];
$sql = "UPDATE users SET name=?, lastname=?, gender=?, birth_date=?, mail=?, address=?, phone_number=? WHERE id=?";
if($stmt = mysqli_prepare($link, $sql)){
mysqli_stmt_bind_param($stmt, "sssssssi", $param_name, $param_lastname, $param_gender, $param_birth, $param_mail, $param_add, $param_phone, $param_id);
$param_name = $_POST["name"];
$param_lastname = $_POST["lastname"];
$param_gender = $_POST["gender"];
$param_birth = $_POST["birth_date"];
$param_mail = $_POST["mail"];
$param_add = $_POST["address"];
$param_phone = $_POST["phone_number"];
$param_id = $id;
if(mysqli_stmt_execute($stmt)){
header("location: index.php");
exit();
} else{
echo "เกิดข้อผิดพลาด กรุณาลองใหม่อีกครั้ง";
}
}
mysqli_stmt_close($stmt);
mysqli_close($link);
}
if(isset($_GET["id"]) && !empty(trim($_GET["id"]))){
$id = trim($_GET["id"]);
$sql = "SELECT * FROM users WHERE id = ?";
if($stmt = mysqli_prepare($link, $sql)){
mysqli_stmt_bind_param($stmt, "i", $param_id);
$param_id = $id;
if(mysqli_stmt_execute($stmt)){
$result = mysqli_stmt_get_result($stmt);
if(mysqli_num_rows($result) == 1){
$row = mysqli_fetch_array($result, MYSQLI_ASSOC);
$name = $row["name"];
$lastname = $row["lastname"];
$gender = $row["gender"];
$birth_date = $row["birth_date"];
$mail = $row["mail"];
$address = $row["address"];
$phone_number = $row["phone_number"];
} else{
header("location: error.php");
exit();
}
} else{
echo "เกิดข้อผิดพลาด กรุณาลองใหม่อีกครั้ง";
}
}
mysqli_stmt_close($stmt);
mysqli_close($link);
} else{
header("location: error.php");
exit();
}
?>
<html lang="en">
<head>
<title>Edit User</title>
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"
integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<script src="https://unpkg.com/gijgo@1.9.13/js/gijgo.min.js" type="text/javascript"></script>
<link href="https://unpkg.com/gijgo@1.9.13/css/gijgo.min.css" rel="stylesheet" type="text/css" />
</head>
<body>
<br />
<div class="container">
<div class="panel panel-primary" style="width:750px;margin:0px auto">
<div class="panel-heading">Edit User</div>
<div class="panel-body">
<form data-toggle="validator" role="form" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>"
method="post">
<div class="form-group">
<label class="control-label">Name</label>
<input class="form-control" value="<?php echo $name; ?>" data-error="Please enter name field."
name="name" placeholder="Name" type="text" required />
<div class="help-block with-errors"></div>
</div>
<div class="form-group">
<label class="control-label">Last Name</label>
<input class="form-control" value="<?php echo $lastname; ?>"
data-error="Please enter lastname field." placeholder="Email" name="lastname" required>
<div class="help-block with-errors"></div>
</div>
<div class="form-group">
<label class="control-label">Gender</label>
<select id="inputState" class="form-control" data-error="Please enter gender field." name="gender"
required style="width:270px;">
<option value="">----Select----</option>
<option value="M" <?php echo ($gender == "M") ? "selected" : ""; ?> selected>Male</option>
<option value="F" <?php echo ($gender == "F" )? "selected" : ""; ?>>Female</option>
</select>
<div class="help-block with-errors"></div>
</div>
<div class="form-group">
<label class="control-label">Birthdate</label>
<div class="form-group">
<input id="datepicker" name="birth_date" value="<?php echo $birth_date; ?>" width="270" required/>
<div class="help-block with-errors"></div>
</div>
</div>
<div class="form-group">
<label class="control-label">E-mail</label>
<input class="form-control" value="<?php echo $mail; ?>"
data-error="Please enter birth date field." placeholder="E-mail" name="mail" required>
<div class="help-block with-errors"></div>
</div>
<div class="form-group">
<label class="control-label">Address</label>
<textarea class="form-control"
data-error="Please enter address field." placeholder="Address" name="address"
required=""><?php echo $address; ?></textarea>
<div class="help-block with-errors"></div>
</div>
<div class="form-group">
<label class="control-label">Phone Number</label>
<input class="form-control" value="<?php echo $phone_number; ?>"
data-error="Please enter birth date field." name="phone_number" maxlength="10"
onkeyup="phone_num_format()" id="phone_number" placeholder="Phone Number" required
style="width:270px;">
<div class="help-block with-errors"></div>
</div>
<div class="form-group">
<input type="hidden" name="id" value="<?php echo $id; ?>" />
<button class="btn btn-primary" type="submit">Submit</button>
</div>
</form>
</div>
</div>
</div>
</body>
</html>
<script>
$('#datepicker').datepicker({
uiLibrary: 'bootstrap',
format: 'yyyy-mm-dd'
});
function phone_num_format() {
var phone = $('#phone_number').val();
if (phone !== '') {
intRegex = /[0-9 -()+]+$/;
if ((phone.length > 10) || (!intRegex.test(phone))) {
alert('Please enter a valid phone number.');
$('#phone_number').val('');
return false;
}
}
}
</script>
\ No newline at end of file
Error!!!!
<?php
// require_once("dbconnect.php");
require_once("database.php");
?>
<html lang="en">
<head>
<title>
Bootstrap Validation example using validator.js
</title>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/1000hz-bootstrap-validator/0.11.5/validator.min.js"></script>
</head>
<body>
<br />
<div class="container">
<div class="panel panel-primary" style="width:auto;margin:0px auto">
<div class="panel-heading">List Users</div>
<div class="panel-body">
<button type="button" class="btn btn-success" onclick="window.location.href='add-user.php'">ADD
USER</button>
<br /><br />
<table class="table table-bordered">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">Name</th>
<th scope="col">Last Name</th>
<th scope="col">Gender</th>
<th scope="col">Birthdate</th>
<th scope="col">E-mail</th>
<th scope="col">Address</th>
<th scope="col">Phone Number</th>
<th scope="col">Actions</th>
</tr>
</thead>
<tbody>
<?php
$sql = "SELECT * FROM users";
if($result = mysqli_query($link, $sql)){
if(mysqli_num_rows($result) > 0){
$order = 1;
while($row = $result->fetch_array()){
?>
<tr>
<th scope="row"><?php echo $order; ?></th>
<td><?php echo $row['name']; ?></td>
<td><?php echo $row['lastname']; ?></td>
<td><?php echo $row['gender'] == "M" ? "Male" : "Female"; ?></td>
<td><?php echo $row['birth_date']; ?></td>
<td><?php echo $row['mail']; ?></td>
<td><?php echo $row['address']; ?></td>
<td><?php echo $row['phone_number']; ?></td>
<td>
<button type="button" class="btn btn-warning"
onclick="window.location.href='edit-user.php?id=<?php echo $row['id']; ?>'">EDIT</button>
<button type="button" class="btn btn-danger"
onclick="window.location.href='delete-user.php?id=<?php echo $row['id']; ?>'">DELETE</button>
</td>
</tr>
<?php
$order++;
}
}else{
?>
<tr>
<td colspan="9" align="center"><span class="label label-danger">Empty Data.</span></td>
</tr>
<?php
}
}
?>
</tbody>
</table>
</div>
</div>
</div>
</body>
</html>
\ No newline at end of file
-- phpMyAdmin SQL Dump
-- version 4.8.4
-- https://www.phpmyadmin.net/
--
-- Host: 127.0.0.1
-- Generation Time: Oct 05, 2019 at 08:59 PM
-- Server version: 10.1.37-MariaDB
-- PHP Version: 5.6.39
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET AUTOCOMMIT = 0;
START TRANSACTION;
SET time_zone = "+00:00";
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;
--
-- Database: `test`
--
-- --------------------------------------------------------
--
-- Table structure for table `users`
--
CREATE TABLE `users` (
`id` int(11) NOT NULL,
`name` varchar(255) NOT NULL,
`lastname` varchar(255) NOT NULL,
`gender` varchar(1) NOT NULL,
`birth_date` date NOT NULL,
`mail` varchar(255) NOT NULL,
`address` mediumtext NOT NULL,
`phone_number` varchar(255) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8 ROW_FORMAT=REDUNDANT;
--
-- Dumping data for table `users`
--
INSERT INTO `users` (`id`, `name`, `lastname`, `gender`, `birth_date`, `mail`, `address`, `phone_number`) VALUES
(12, 'c,gfdfgh', 'gfdfghvgfd', 'M', '2019-09-30', 'xhffgdz', 'ffdzdgzfd', '4456456665');
--
-- Indexes for dumped tables
--
--
-- Indexes for table `users`
--
ALTER TABLE `users`
ADD PRIMARY KEY (`id`);
--
-- AUTO_INCREMENT for dumped tables
--
--
-- AUTO_INCREMENT for table `users`
--
ALTER TABLE `users`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=13;
COMMIT;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment