ThaiSEOBoard.com

พัฒนาเว็บไซต์ => Programming => ข้อความที่เริ่มโดย: bwnm29 ที่ 22 ตุลาคม 2019, 00:20:42



หัวข้อ: ช่วยด้วยค่ะ สร้างไฟล์คอนแท็บบันทึกข้อมูลลงดาต้าเบส แต่ไม่ขึ้นไรเลย
เริ่มหัวข้อโดย: bwnm29 ที่ 22 ตุลาคม 2019, 00:20:42
เราสร้างไฟล์คอนแท็บ  เพื่อหาค่าจากตาราง hm2_history ดูว่า ฟิลด์ type = commission มั้ย ถ้าใช่ เพิ่มเรคคอร์ดลงในดาต้าเบส hm2_history ค่าทุกอย่างเหมือนเดิม ต่างกันแค่จำนวนเงินเป็นติดลบ
จากนั้นเอาข้อมูลคล้ายๆแบบเดิมไปเพิ่มในอีกตาราง คือ ตาราง hm2_deposit แต่โค้ดที่เราเขียนไม่รู้ถูกต้องมั้ย มันขึ้นแค่ว่า connection susccess พอลองกดไปดู ไม่มีอะไรเพิ่มในต้าต้าเบสเลย แก้ตรงไหนคะ 

โค๊ด:
<?php
$servername 
"localhost";
$username "tinybaht";
$password "212224";

function 
setChecked($conn,$params){
$s $conn->prepare("UPDATE `hm2_history`
SET history_ref_id=-1
WHERE id=:id
"
);
$s->execute($params);
}

try {
    
$conn = new PDO("mysql:host=$servername;dbname=tinybaht_findroom"$username$password);
    
// set the PDO error mode to exception
    
$conn->setAttribute(PDO::ATTR_ERRMODEPDO::ERRMODE_EXCEPTION);
    echo 
"Connected successfully";
    }
catch(
PDOException $e)
    {
    echo 
"Connection failed: " $e->getMessage();


    
$stmt $conn->prepare("SELECT parent,name FROM hm2_plans");
    
$stmt->execute();
    
$stmt->setFetchMode(PDO::FETCH_ASSOC);
    
$a $stmt->fetchAll();
$plans = array();
foreach($a as $i){
$plans[$i['parent']] = $i['name'];
}

    
$stmt $conn->prepare("SELECT * FROM hm2_history WHERE id NOT IN(SELECT history_ref_id FROM hm2_history WHERE history_ref_id > 0) AND type='commissions' ");
    
$stmt->execute();
    
$stmt->setFetchMode(PDO::FETCH_ASSOC);
    
$rows $stmt->fetchAll();
    foreach(
$rows as $k=>$v) {


//history

$s $conn->prepare("INSERT INTO `hm2_history`
SET `user_id`=:user_id,
`amount`=:amount,
`type`=:type,
`description`=:description,
`actual_amount`=:actual_amount,
`date`=:date,
`ec`=:ec,
`deposit_id`=:deposit_id,
`rate`=:rate,
`history_ref_id`=:history_ref_id

"
);
$x = array(
'user_id'=>$v['user_id'],
'type'=>'depoit',
'amount'=> -$v['amount'],
'description'=>'Deposit from plan',
'actual_amount'=> -$v['actual_amount'],
'date'=>$date,
'ec'=>999,
'deposit_id'=>$lastDepositId,
'rate'=>1.0,
);
$s->execute($x);



    
//deposit
$s $conn->prepare("INSERT INTO `hm2_deposits`
SET `user_id`=:user_id,
`type_id`=:type_id,
`deposit_date`=:deposit_date,
`last_pay_date`=:last_pay_date,
`status`=:status,
`q_pays`=:q_pays,
`amount`=:amount,
`actual_amount`=:actual_amount,
`ec`=:ec,
`compound`=:compound,
`dde`=:dde,
`unit_amount`=:unit_amount,
`bonus_flag`=:bonus_flag,
`init_amount`=:init_amount,
`ref_id`=:ref_id,
`history_ref_id`=:history_ref_id
"
);
$v['type_id'] = 9;
$v['ref_id'] = 0;
$v['history_ref_id'] = $v['id'];
$v['amount'] = $v['amount'];
$v['actual_amount'] = $v['actual_amount'];
$v['init_amount'] = $v['init_amount'];
$v['bonus_flag'] = 1;
unset($v['id']);
$s->execute($v);
$lastDepositId $conn->lastInsertId();
    }

}
?>



หัวข้อ: Re: ช่วยด้วยค่ะ สร้างไฟล์คอนแท็บบันทึกข้อมูลลงดาต้าเบส แต่ไม่ขึ้นไรเลย
เริ่มหัวข้อโดย: smapan ที่ 22 ตุลาคม 2019, 17:22:32
อ่านจากโค้ดตาลายมาก  :P

แนะนำทั่วๆไปในการหา Bug ละกัน
ลองเอา sql แต่ละคำสั่งใน phpmyadmin ทีละชุดนะ
debug นั่นแหละ


หัวข้อ: Re: ช่วยด้วยค่ะ สร้างไฟล์คอนแท็บบันทึกข้อมูลลงดาต้าเบส แต่ไม่ขึ้นไรเลย
เริ่มหัวข้อโดย: Twenty-One ที่ 22 ตุลาคม 2019, 19:04:57
โค้ดยาวเหมือนกันครับ ผมว่าลองรันทีละส่วน แล้วดูก่อนจะได้รู้ว่าผิดตรงไหน
รันพรวดเดียวยากครับแบบนี้