 |
|
Code (PHP)
<?php
if(!isset($_SESSION)){
session_start();
}
require './config/function.php';
require './config/connect.php';
$result = $con->prepare("SELECT * FROM member WHERE id=' ".$_SESSION['user']['id']." ' ");
$result->execute();
$rs = $result->fetch();
if(isset($_POST) && isset($_POST['a'])){
$a = array(
'date'=>$_POST['a']['date'],
'time_in'=>$_POST['a']['time_in'],
'time_out'=>$_POST['a']['time_out'],
'games'=>$_POST['a']['games'],
'dessert'=>$_POST['a']['dessert'],
'print'=>$_POST['a']['print'],
'remark'=>$_POST['a']['remark'],
'gameslost'=>$_POST['a']['gameslost'],
'dessertlost'=>$_POST['a']['dessertlost'],
'printlost'=>$_POST['a']['printlost']
);
$result1 = $con->prepare("INSERT INTO revenue(username,date,time_in,time_out,games,dessert,print,remark,gameslost,dessertlost,printlost,member_id,create_at)
VALUES(' ".$rs['username']." ',:date,:time_in,:time_out,:games,:dessert,:print,:remark,:gameslost,:dessertlost,:printlost,' ".$rs['id']." ',' ".date("Y-m-d H:i:s")." ' ) ");
$result1->execute($a);
if($result1!==false){
$_SESSION['flash']['type'] = 'เพิ่มข้อมูลออกกะเรียบร้อย';
$_SESSION['flash']['msg'] = 'success';
redirect_to('index.php');
}else{
$_SESSION['flash']['type'] = 'เกิดข้อผิดพลาดในการเพิ่มข้อมูลหรือใส่ข้อมูลไม่ครบถ้วน';
$_SESSION['flash']['msg'] = 'danger';
redirect_to('index.php');
}
}
อันนี้เป็น code หน้าที่ผมจะทำการเพิ่มข้อมูลนะครับ แต่ว่าพอ กดเพิ่มข้อมูลไปแล้ว มันขึ้น เพิ่มข้อมูลเรียบร้อย แต่ข้อมูลไม่เข้า database ครับ
$_SESSION มันใช้วิธีประกาศแบบเก็บไว้ใน fetch(); นะครับ
Tag : PHP, MySQL
|
|
 |
 |
 |
 |
Date :
2016-08-13 18:27:44 |
By :
oyzceep |
View :
706 |
Reply :
1 |
|
 |
 |
 |
 |
|
|
|
 |