|
 |
|
อยากจะสอบถามเรื่อง loop ครับ (ติดปัญหานี้มานานมาก) |
|
 |
|
|
 |
 |
|
จากตัวอย่าง โค้ต
Code (PHP)
<?php
//Show all error, remove it once you finished you code.
ini_set('display_errors', 1);
$mysecretteststring = "my secret password";
include_once 'config/config.php';
//Include TrueWallet class.
include_once('config/TrueWallet.php');
$con = new mysqli($servername,$server_user,$server_password,$mysql_dbname);
$wallet = new TrueWallet();
//Login with your username and password.
$username = $tw_email;
$password = $tw_pass;
//////////////
$t_id = $_POST['tw_id'];
$nick = $_POST['nick'];
//////////////
//Logout incase your previous session still exist, no need if you only use 1 user.
$wallet->logout();
//Login into TrueWallet
if($wallet->login($username,$password)){
if($transaction = $wallet->get_transactions()){
$sql_r = "SELECT * FROM history_wallet WHERE report='$t_id'";
$res_r = mysqli_query($con, $sql_r);
if (mysqli_num_rows($res_r) > 0) {
echo "<img src='img/truewallet/Sign-Error-icon.png' width='90' height='90'><br>";
echo "<font size='4'>ขออภัยรหัสอ้างถูกใช้งานไปแล้ว</font>";
} else {
for ($i=1; $i <= 10; $i++) { //จำนวนที่ดึกมาเช็ค
$report = $wallet->get_report($transaction[$i]->reportID);
$ref_t = $report->section4->column2->cell1->value;
$money = $report->section3->column1->cell1->value;
if ($ref_t === $t_id) {
echo "ทำรายการสำเร็จ";
break;
} else {
echo "รหัสอ้างอิงผิด";
break;
}
}
}
}
//Logout
$wallet->logout();
}else{
echo 'Login Failed!';
}
?>
ปัญหา คือ เมื่อผม กรอก $t_id (form) ตรงกับค่า $ref_t ไม่ว่า $t_id จะตรงกับค่า $ref_t หรือไหม มันก็จะขึ้นแต่ค่า รหัสอ้างอิงผิด
มีวิธีแก้ไหมครับ
Tag : PHP, MySQL, HTML

|
ประวัติการแก้ไข 2018-06-03 18:41:16
|
 |
 |
 |
 |
Date :
2018-06-03 18:39:52 |
By :
AloneSpace |
View :
550 |
Reply :
3 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
$t_id = $_POST['tw_id']; รับค่าแบบนี้จะได้ type เป็น string
$ref_t = $report->section4->column2->cell1->value; บันทัดนี้ได้ค่ามาเป็นอะไรไม่รู้ แต่คาดว่าน่าจะเป็น int
if ($ref_t === $t_id) { ส่วนตรงนี้เปรียบเทียบแบบตรวจสอบ type ด้วย
ลอง แบบนี้ ไม่ต้องตรวจสอบ type ของตัวแปร เอาแค่ค่าเหมือนกันก็พอ
if ($ref_t == $t_id) {
|
 |
 |
 |
 |
Date :
2018-06-03 20:38:33 |
By :
Chaidhanan |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
มันก็ยังขึ้นเหมือนเดิมอะครับ ไม่ว่าเรากรอก $t_id ตรงกับข้อมูล $ref_t
echo "รหัสอ้างอิงผิด";
|
 |
 |
 |
 |
Date :
2018-06-03 21:27:09 |
By :
AloneSpace |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
echo "รหัสอ้างอิงผิด:" . $ref_t .':'.$t_id .':'.strlen($ref_t).':'.strlen($t_id);
ให้มันแสดงข้อมูลจำเพาะมาตรวจสอบ
|
 |
 |
 |
 |
Date :
2018-06-03 22:03:04 |
By :
Chaidhanan |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 01
|