|
![](/images/resource/spacer.gif) |
|
มีปัญหากับ PDO lastInsertId() ค่าออกเป็น 0 ไม่ออกเป็น id สุดท้าย |
|
![](/images/resource/viewboard_01.gif?v=1001) |
|
|
![](/images/resource/viewboard_03.gif?v=1001) |
![](/images/resource/viewboard_04.gif?v=1001) |
|
ตามรูปเลยครับ ออกเป็น 0 ไอดีมันไม่ต่ออันสุดท้าย ฟิลด์ไม่เป็นเป็นแบบ auto increment ครับ
![กกกก กกกก](https://www.thaicreate.com/upload/stock/20150729105050.png?v=1001)
Code (PHP)
<?php
include 'connect.php';
$machine_id = htmlspecialchars($_POST['machine_id']);
$memtotal = htmlspecialchars($_POST['memtotal']);
$fullname = htmlspecialchars($_SESSION['fullname']);
try {
$insertM = $db->prepare('INSERT INTO tbl_logs(machine_id,start,staff,member_total) VALUES (:machine_id,NOW(),:fullname,:memtotal)');
$insertM->bindParam(':machine_id',$machine_id,PDO::PARAM_STR);
$insertM->bindParam(':fullname',$fullname,PDO::PARAM_STR);
$insertM->bindParam(':memtotal',$memtotal,PDO::PARAM_INT);
$q = $insertM->execute();
echo $lastId = $db->lastInsertId();
if($q)
{
//echo "<script>alert('Save successfully!');</script>";
echo "<script>window.top.window.showResult('1');</script>";
}
else
{
//echo "<script>alert('Error! Cannot save data');</script>";
echo "<script>window.top.window.showResult('2');</script>";
}
}
catch(PDOException $e)
{
echo "Error: " . $e->getMessage();
}
$db = null;
?>
Tag : PHP, MySQL
![](/images/adv.jpg?v=1001)
|
|
![](/images/resource/blockviewtopic_01.gif?v=1001) |
![](/images/resource/blockviewtopic_02.gif?v=1001) |
![](/images/resource/blockviewtopic_03.gif?v=1001) |
![](/images/resource/blockviewtopic_04.gif?v=1001) |
Date :
2015-07-29 17:33:45 |
By :
littlebeer |
View :
1246 |
Reply :
1 |
|
![](/images/resource/blockviewtopic_06.gif?v=1001) |
![](/images/resource/blockviewtopic_07.gif?v=1001) |
![](/images/resource/blockviewtopic_08.gif?v=1001) |
![](/images/resource/blockviewtopic_09.gif?v=1001) |
|
|
|
![](/images/resource/viewboard_06.gif?v=1001) |
![](/images/resource/viewboard_07.gif?v=1001) |
|
![](/images/resource/viewboard_08.jpg?v=1001) |
![](/images/resource/viewboard_09.gif?v=1001) |
![](/images/resource/viewboard_01.gif?v=1001) |
|
|
![](/images/resource/viewboard_03.gif?v=1001) |
![](/images/resource/viewboard_04.gif?v=1001) |
|
ก็ทำให้เป็น auto increment เลยครับ
|
![](/images/resource/blockviewtopic_01.gif?v=1001) |
![](/images/resource/blockviewtopic_02.gif?v=1001) |
![](/images/resource/blockviewtopic_03.gif?v=1001) |
![](/images/resource/blockviewtopic_04.gif?v=1001) |
Date :
2015-07-29 17:41:25 |
By :
NewbiePHP |
|
![](/images/resource/blockviewtopic_06.gif?v=1001) |
![](/images/resource/blockviewtopic_07.gif?v=1001) |
![](/images/resource/blockviewtopic_08.gif?v=1001) |
![](/images/resource/blockviewtopic_09.gif?v=1001) |
|
|
![](/images/resource/viewboard_06.gif?v=1001) |
![](/images/resource/viewboard_07.gif?v=1001) |
|
![](/images/resource/viewboard_08.jpg?v=1001) |
![](/images/resource/viewboard_09.gif?v=1001) |
|
|
|
![](/images/digitalocean-banner.jpg)
|
Load balance : Server 05
|