 |
[PHP]
ปรึกษาเรื่อง Update ข้อมูล แจ้งเตือน undefined index update_Id ซึ่ง update_id เรียกใช้งานถูกครับ |
|
 |
|
|
 |
 |
|
ปรึกษาเรื่อง Update ข้อมูล แจ้งเตือน undefined index update_id ซึ่ง update_Id เรียกใช้งานถูกครับ
สิ่งที่เจอคือ
1. update ข้อมูลผ่าน แต่ข้อมูลไม่ถูก update ครับ
2. หลังแจ้ง update ข้อมูลเรียบร้อย จะขึ้น แจ้งเตือน undefined index update_id ตามมาครับ
ภาพที่ 1

Code (index.php ส่วนการ update_id)
1. <td>
2. <div class = "btn-group" role= "group" aria-label= "Basic mixed styles example" >
3. <a href= "form-edit.php?update_id=<?php echo $row[" Id "]; ?>" type= "button" class = "btn btn-danger text-white" ><i class = "far fa-edit" ></i>
4. </a>
5. <a type= "button" class = "btn btn-warning text-white" ><i class = "far fa-edit" ></i>
6. </a>
7. </div>
8. </td>
Code (form.php)
01. <form action= "edit.php" method= "POST" >
02. <div class = "card-body" >
03. <div class = "row" >
04. <div class = "col-md-6 px-1 px-md-5" >
05.
06. <div class = "form-group" >
07. <label for = "computername" >Computer Name</label>
08. <input type= "text" class = "form-control" name= "txt_Computername" value= "<?php echo $Computername; ?>" required>
09. </div>
10. <div class = "form-group" >
11. <label for = "username" >Username</label>
12. <input type= "text" class = "form-control" name= "txt_Username" value= "<?php echo $Username; ?>" required>
13. </div>
14. <div class = "form-group" >
15. <label for = "manufacturer" >Manufacturer</label>
16. <input type= "text" class = "form-control" name= "txt_Manufacturer" value= "<?php echo $Manufacturer; ?>" required>
17. </div>
18. <div class = "form-group" >
19. <label for = "model" >Model</label>
20. <input type= "text" class = "form-control" name= "txt_Model" value= "<?php echo $Model; ?>" required>
21. </div>
22.
23. </div>
24.
25. <div class = "col-md-6 px-1 px-md-5" >
26. <div class = "form-group" >
27. <label for = "serialnumber" >Serial Number</label>
28. <input type= "text" class = "form-control" name= "txt_SN" value= "<?php echo $SN; ?>" required>
29. </div>
30.
31. <div class = "form-group" >
32. <label for = "cpu" >CPU</label>
33. <input type= "text" class = "form-control" name= "txt_CPU" value= "<?php echo $CPU; ?>" required>
34. </div>
35.
36. <div class = "form-group" >
37. <label for = "os" >OS</label>
38. <input type= "text" class = "form-control" name= "txt_OS" value= "<?php echo $OS; ?>" required>
39. </div>
40.
41. </div>
42. </div>
43. <!-- <div class = "card-footer" >
44. <button type= "submit" name= "btn_update" class = "btn btn-primary btn-block mx-auto w-50" value= "update" >บันทึกข้อมูล</button>
45. </div> -->
46. </div>
47. <div class = "card-footer" >
48. <button type= "submit" name= "btn_update" class = "btn btn-primary btn-block mx-auto w-50" value= "update" >บันทึกข้อมูล</button>
49. </div>
50. </form>
Code (edit.php เรียกใช้งานหน้า form.php)
01. <?php
02. require_once ( '../../../database/connection.php' );
03.
04. $up = $_REQUEST [ 'update_id' ];
05.
06. if (isset( $_REQUEST [ 'update_id' ])){
07.
08. $sql = "SELECT * FROM masterpc WHERE Id = $up; " ;
09. $result = $conn ->query( $sql );
10. while ( $row = $result ->fetch_array(MYSQLI_ASSOC)){
11.
12. $Computername = $row [ "Computername" ];
13. $Username = $row [ "Username" ];
14. $Manufacturer = $row [ "Manufacturer" ];
15. $Model = $row [ "Model" ];
16. $SN = $row [ "SN" ];
17. $CPU = $row [ "CPU" ];
18. $OS = $row [ "OS" ];
19.
20.
21. }
22.
23. }
24.
25.
26. if (isset( $_REQUEST [ 'btn_update' ])) {
27.
28.
29. $Computername_up = $_REQUEST [ 'txt_Computername' ];
30. $Username_up = $_REQUEST [ 'txt_Username' ];
31. $Manufacturer_up = $_REQUEST [ 'txt_Manufacturer' ];
32. $Model_up = $_REQUEST [ 'txt_Model' ];
33. $SN_up = $_REQUEST [ 'txt_SN' ];
34. $CPU_up = $_REQUEST [ 'txt_CPU' ];
35. $OS_up = $_REQUEST [ 'txt_OS' ];
36.
37. $sqli = "UPDATE masterpc SET Computername='$Computername_up',Username='$Username_up',Manufacturer='$Manufacturer_up',Model='$Model_up',SN='$SN_up',CPU='$CPU_up',OS='$OS_up' WHERE Id = '$up'" ;
38.
39. if (mysqli_query( $conn , $sqli )) {
40. echo "<script>alert('แก้ไขข้อมูลสำเร็จ...'); window.location ='index.php';</script>" ;
41.
42. } else {
43. echo "Error: " . $sqli . "<br>" . mysqli_error( $conn );
44. }
45.
46. mysqli_close( $conn );
47. }
48.
49. ?>
Tag : PHP, MySQL
|
ประวัติการแก้ไข 2021-10-25 09:35:22
|
 |
 |
 |
 |
Date :
2021-10-25 09:28:59 |
By :
TeeTs |
View :
1111 |
Reply :
49 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
บรรทัดที่ 4 ของ edit.php
$up = $_REQUEST['update_id'];
ค่า update_id ไม่ได้ส่งมาด้วย
ถ้าใช้ form ก็ต้องมี input ที่มี name="update_id"
|
 |
 |
 |
 |
Date :
2021-10-25 20:21:07 |
By :
{Cyberman} |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ตอนนี้พูดถึงหน้า form เท่านั้นครับ
ลองค้นหา update_id ให้เจอครับ
|
 |
 |
 |
 |
Date :
2021-10-26 08:31:27 |
By :
{Cyberman} |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (form-edit.php)
01. <form action= "edit.php" method= "POST" >
02. <div class = "card-body" >
03. <div class = "row" >
04. <div class = "col-md-6 px-1 px-md-5" >
05.
06. <div class = "form-group" >
07. <label for = "computername" >Computer Name</label>
08. <input type= "text" class = "form-control" name= "txt_Computername" value= "<?php echo $Computername; ?>" required>
09. </div>
10. <div class = "form-group" >
11. <label for = "username" >Username</label>
12. <input type= "text" class = "form-control" name= "txt_Username" value= "<?php echo $Username; ?>" required>
13. </div>
14. <div class = "form-group" >
15. <label for = "manufacturer" >Manufacturer</label>
16. <input type= "text" class = "form-control" name= "txt_Manufacturer" value= "<?php echo $Manufacturer; ?>" required>
17. </div>
18. <div class = "form-group" >
19. <label for = "model" >Model</label>
20. <input type= "text" class = "form-control" name= "txt_Model" value= "<?php echo $Model; ?>" required>
21. </div>
22.
23. </div>
24.
25. <div class = "col-md-6 px-1 px-md-5" >
26. <div class = "form-group" >
27. <label for = "serialnumber" >Serial Number</label>
28. <input type= "text" class = "form-control" name= "txt_SN" value= "<?php echo $SN; ?>" required>
29. </div>
30.
31. <div class = "form-group" >
32. <label for = "cpu" >CPU</label>
33. <input type= "text" class = "form-control" name= "txt_CPU" value= "<?php echo $CPU; ?>" required>
34. </div>
35.
36. <div class = "form-group" >
37. <label for = "os" >OS</label>
38. <input type= "text" class = "form-control" name= "txt_OS" value= "<?php echo $OS; ?>" required>
39. </div>
40.
41. </div>
42. </div>
43. </div>
44. <div class = "card-footer" >
45. <!-- <input type= "hidden" name= "update_id" value= "<?php echo row[" Id "]; ?>" >
46. <input type= "hidden" name= "update_id" value= "<?php echo $Id; ?>" > -->
47.
48. <button type= "submit" name= "btn_update" class = "btn btn-primary btn-block mx-auto w-50" value= "update" >บันทึกข้อมูล</button>
49. </div>
50. </form>
|
 |
 |
 |
 |
Date :
2021-10-26 09:37:17 |
By :
TeeTs |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ตอบความคิดเห็นที่ : 9 เขียนโดย : Guest เมื่อวันที่ 2021-10-26 10:20:13
รายละเอียดของการตอบ ::
ค่า Id มาครับ
ภาพที่ 1
เวลาคลิกแก้ไข ไปยังหน้า form edit.php || form-edit.php?update_id=1 Id ก็มาครับ ผิดจุดไหนแล้วเนี้ย
Code (edit.php)
01. <?php
02. require_once ( '../../../database/connection.php' );
03.
04. $up = $_REQUEST [ 'update_id' ];
05. echo $_REQUEST [ 'update_id' ];
06.
07. if (isset( $_REQUEST [ 'update_id' ])){
08.
09. $sql = "SELECT * FROM masterpc WHERE Id = $up; " ;
10. $result = $conn ->query( $sql );
11. while ( $row = $result ->fetch_array(MYSQLI_ASSOC)){
12.
13. $Computername = $row [ "Computername" ];
14. $Username = $row [ "Username" ];
15. $Manufacturer = $row [ "Manufacturer" ];
16. $Model = $row [ "Model" ];
17. $SN = $row [ "SN" ];
18. $CPU = $row [ "CPU" ];
19. $OS = $row [ "OS" ];
20.
21.
22. }
23.
24. }
25.
26.
27. if (isset( $_REQUEST [ 'btn_update' ])) {
28.
29.
30. $Computername_up = $_REQUEST [ 'txt_Computername' ];
31. $Username_up = $_REQUEST [ 'txt_Username' ];
32. $Manufacturer_up = $_REQUEST [ 'txt_Manufacturer' ];
33. $Model_up = $_REQUEST [ 'txt_Model' ];
34. $SN_up = $_REQUEST [ 'txt_SN' ];
35. $CPU_up = $_REQUEST [ 'txt_CPU' ];
36. $OS_up = $_REQUEST [ 'txt_OS' ];
37.
38. $sqli = "UPDATE masterpc SET Computername='$Computername_up',Username='$Username_up',Manufacturer='$Manufacturer_up',Model='$Model_up',SN='$SN_up',CPU='$CPU_up',OS='$OS_up' WHERE Id = '$up'" ;
39.
40. if (mysqli_query( $conn , $sqli )) {
41. echo "<script>alert('แก้ไขข้อมูลสำเร็จ...'); window.location ='index.php';</script>" ;
42.
43. } else {
44. echo "Error: " . $sqli . "<br>" . mysqli_error( $conn );
45. }
46.
47. mysqli_close( $conn );
48. }
49.
50. ?>
|
ประวัติการแก้ไข 2021-10-26 19:27:20 2021-10-26 19:27:52 2021-10-26 19:33:50 2021-10-26 19:33:55
 |
 |
 |
 |
Date :
2021-10-26 19:24:36 |
By :
TeeTs |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เอา
$_REQUEST['update_id'];
ไว้ใน if (isset()) {
Code (PHP)
01. <?php
02. require_once ( '../../../database/connection.php' );
03.
04. if (isset( $_REQUEST [ 'update_id' ])) {
05. $sql = "SELECT * FROM `masterpc` WHERE `Id` = '" . $_REQUEST ['update_id ']."' ";
06. $result = $conn ->query( $sql );
07. while ( $row = $result ->fetch_array(MYSQLI_ASSOC)) {
08. $Computername = $row [ "Computername" ];
09. $Username = $row [ "Username" ];
10. $Manufacturer = $row [ "Manufacturer" ];
11. $Model = $row [ "Model" ];
12. $SN = $row [ "SN" ];
13. $CPU = $row [ "CPU" ];
14. $OS = $row [ "OS" ];
15. }
16. }
17.
18. if (isset( $_REQUEST [ 'btn_update' ])) {
19. $Computername_up = $_REQUEST [ 'txt_Computername' ];
20. $Username_up = $_REQUEST [ 'txt_Username' ];
21. $Manufacturer_up = $_REQUEST [ 'txt_Manufacturer' ];
22. $Model_up = $_REQUEST [ 'txt_Model' ];
23. $SN_up = $_REQUEST [ 'txt_SN' ];
24. $CPU_up = $_REQUEST [ 'txt_CPU' ];
25. $OS_up = $_REQUEST [ 'txt_OS' ];
26.
27. echo $sqli = "UPDATE `masterpc` SET
28. `Computername` = '{$Computername_up}' ,
29. `Username` = '{$Username_up}' ,
30. Manufacturer` = '{$Manufacturer_up}' ,
31. `Model` = '{$Model_up}' ,
32. `SN` = '{$SN_up}' ,
33. `CPU` = '{$CPU_up}' ,
34. `OS` = '{$OS_up}'
35. WHERE
36. `Id` = '".$_REQUEST[' update_id '].' ";
37.
38. if (mysqli_query( $conn , $sqli )) {
39. echo "<script>alert('แก้ไขข้อมูลสำเร็จ...'); window.location ='index.php';</script>" ;
40. } else {
41. echo "Error: " . $sqli . "<br>" . mysqli_error( $conn );
42. }
43. mysqli_close( $conn );
44. }
45. ?>
|
 |
 |
 |
 |
Date :
2021-10-27 10:29:26 |
By :
Guest |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
<?php
echo 'past ', __LINE__, json_encode( ['rq'=>$_REQUEST, 'post'=>$_POST, 'get'=>$_GET]),'<br>';
ลองตรวจสอบ ข้อมูลที่มาก่อน ว่าถูกต้อง กับชนิดการ request ไหม
จริงๆ แล้ว จาก no 14 ถ้าลองทำก็ควรจะรู้ว่าอะไรเป็นอะไรแล้ว
|
 |
 |
 |
 |
Date :
2021-10-27 11:10:11 |
By :
Chaidhanan |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
จาก No 16 ได้ข้อมูลยังไง สำหรับ หน้า Edit
|
 |
 |
 |
 |
Date :
2021-10-27 17:13:05 |
By :
Chaidhanan |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
คห. 14 ให้ echo คำสั่ง UPDATE มาดู ทำไมไม่ทำตามล่ะครับ
ในนั้นมันมี echo อยู่ ทำแล้วก็จะเห็นเลยว่าคำสั่ง UPDATE เราถูกมั้ย?
ผล echo เป็นยังไงเอามาดู
แล้วถ้าจะให้ดี ที่แก้ไขล่าสุดเป็นยังไงเอาโค้ดมาลงด้วยครับ
สรุป
1. ทำตาม คห 14 เอาผล echo ของคำสั่ง UPDATE มาดู.
เบื้องต้นตรงนี้จะได้ตรวจสอบเองได้ด้วยว่าคำสั่ง sql UPDATE ถูกมั้ย
2. แล้วก็โค้ดที่แก้ไขล่าสุด
3. หน้าฟอร์มแก้ไขเป็นยังไง ถูกต้องมั้ย?
4. หลังจากกด submit แล้วได้อะไร? จากโค้ดมันควรจะได้ alert สำเร็จหรือ error ก็เอามาลงว่ามันได้อะไร
|
ประวัติการแก้ไข 2021-10-29 00:46:21
 |
 |
 |
 |
Date :
2021-10-29 00:37:27 |
By :
mr.v |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ตอบความคิดเห็นที่ : 21 เขียนโดย : mr.v เมื่อวันที่ 2021-10-29 00:37:27
รายละเอียดของการตอบ ::
ตอบที่ no.15 แล้วครับ อาจตอบสั้นไป
2. แล้วก็โค้ดที่แก้ไขล่าสุด => อันนี้เดี๋ยวทำใหม่ครับ เพราะตอนแรกทำแล้วไม่ได้ ลบทิ้งแล้ว เลยทำใหม่หมดครับ
3. หน้าฟอร์มแก้ไขเป็นยังไง ถูกต้องมั้ย? => ฟอร์มถูกอยู่แล้ว อิงจาก ฟอร์ม insert เลย เพียงเปลี่ยนใน input ตรง value="echo........" และตรง btn name="........." และ ฟอร์ม method post
4. หลังจากกด submit แล้วได้อะไร? จากโค้ดมันควรจะได้ alert สำเร็จหรือ error ก็เอามาลงว่ามันได้อะไร => ไม่รู้จัก update_id ตาม code php ล่างครับ
Code (PHP)
01.
02.
03. if (isset( $_REQUEST [ 'update_id' ]))
04.
05. or
06.
07. WHERE `Id` = '".$_REQUEST[' update_id ']."'
08.
09. or
10.
11. echo $sqli = "UPDATE `masterpc` SET
12. `Computername` = '{$Computername_up}' ,
13. `Username` = '{$Username_up}' ,
14. Manufacturer` = '{$Manufacturer_up}' ,
15. `Model` = '{$Model_up}' ,
16. `SN` = '{$SN_up}' ,
17. `CPU` = '{$CPU_up}' ,
18. `OS` = '{$OS_up}'
19. WHERE
20. `Id` = '".$_REQUEST[' update_id '].' ";
21.
22. or
23. '{$Computername_up}'
|
ประวัติการแก้ไข 2021-10-29 09:09:06
 |
 |
 |
 |
Date :
2021-10-29 08:59:40 |
By :
TeeTs |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
จะเขียนย่อๆให้ไปเทียบเอานะ
Code (PHP) form-edit.php
1. <form action= "edit.php" method= "post" >
2.
3.
4. <input type= "hidden" name= "update_id" value= "<?php echo $_REQUEST['update_id']; ?>" >
5.
6. <button type= "submit" name= "btn_update" value= "update" >Submit button, class ไปใส่เอาเองนะ</button>
7. </form>
หน้า form.php ก็เทียบ input ที่ต้องมีกับปุ่ม เอาให้แม่น แล้วหน้า edit.php ก็เอาผลลัพธ์ของโค้ดข้างล่างนี้มาดู
Code (PHP) edit.php
01. <?php
02. require_once ( '../../../database/connection.php' );
03.
04. $update_id = (isset( $_REQUEST [ 'update_id' ]) ? $_REQUEST [ 'update_id' ] : null);
05.
06. if (! empty ( $update_id )){
07. $sql = "SELECT * FROM masterpc WHERE Id = $update_id; " ;
08. $result = $conn ->query( $sql );
09. while ( $row = $result ->fetch_array(MYSQLI_ASSOC)){
10. $Computername = $row [ "Computername" ];
11. $Username = $row [ "Username" ];
12. $Manufacturer = $row [ "Manufacturer" ];
13. $Model = $row [ "Model" ];
14. $SN = $row [ "SN" ];
15. $CPU = $row [ "CPU" ];
16. $OS = $row [ "OS" ];
17. }
18. echo 'ไชโย $update_id ไม่ว่างเปล่า! ' . $update_id . '<br>' . "\n" ;
19. } else {
20. echo '$update_id ทำไมว่างเปล่าล่ะ?<br>' . "\n" ;
21. }
22.
23. echo 'REQUEST:<pre>' . print_r( $_REQUEST , true) . '</pre>' ;
24. echo 'GET:<pre>' . print_r( $_GET , true) . '</pre>' ;
25. echo 'POST:<pre>' . print_r( $_POST , true) . '</pre>' ;
26.
27.
|
ประวัติการแก้ไข 2021-10-29 11:21:06 2021-10-29 11:23:48
 |
 |
 |
 |
Date :
2021-10-29 11:06:52 |
By :
mr.v |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ป้องกัน sql injection ด้วยนะครับ
Code (PHP)
01. $sqli = 'UPDATE masterpc SET Computername=?,Username=?,Manufacturer=?,Model=?,SN=?,CPU=?,OS=? WHERE Id = ?' ;
02. $stmt = $conn ->prepare( $sqli );
03. if ( $stmt ->error>0){
04. print_r([ $stmt ->error, $sqli , $datas ]); exit ;
05. }
06. $stmt ->bind_param( 'sssssssi' , $Computername_up , $Username_up , $Manufacturer_up , $Model_up , $SN_up , $CPU_up , $OS_up , $up );
07. $stmt ->execute();
08. if ( $stmt ->error>0){
09. print_r([ $stmt ->error, $sqli , $Computername_up , $Username_up , $Manufacturer_up , $Model_up , $SN_up , $CPU_up , $OS_up , $up ]); exit ;
10. }
|
 |
 |
 |
 |
Date :
2021-10-29 16:54:47 |
By :
Chaidhanan |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
สรุปเคสนี้เดาว่าเกิดจากไม่มี INPUT ที่เก็บค่า id ที่ต้องการอัพเดต จึงไม่ได้ส่งค่าไปครับ
เช่น
<input type="hidden" name="update_id" value="<?php echo $_REQUEST['update_id']; ?>">
|
 |
 |
 |
 |
Date :
2021-10-30 14:47:23 |
By :
{Cyberman} |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Quote:จาก No.14 ลองทำดูครับ ผิด syntax อะไรครับ
ภาพ

Code (edit.php)
01. <?php
02. require_once ( '../../../database/connection.php' );
03.
04. if (isset( $_REQUEST [ 'update_id' ])) {
05. $sql = "SELECT * FROM `masterpc` WHERE `Id` = '" . $_REQUEST ['update_id ']."' ";
06. $result = $conn ->query( $sql );
07. while ( $row = $result ->fetch_array(MYSQLI_ASSOC)) {
08. $Computername = $row [ "Computername" ];
09. $Username = $row [ "Username" ];
10. $Manufacturer = $row [ "Manufacturer" ];
11. $Model = $row [ "Model" ];
12. $SN = $row [ "SN" ];
13. $CPU = $row [ "CPU" ];
14. $OS = $row [ "OS" ];
15. }
16. }
17.
18. if (isset( $_REQUEST [ 'btn_update' ])) {
19. $Computername_up = $_REQUEST [ 'txt_Computername' ];
20. $Username_up = $_REQUEST [ 'txt_Username' ];
21. $Manufacturer_up = $_REQUEST [ 'txt_Manufacturer' ];
22. $Model_up = $_REQUEST [ 'txt_Model' ];
23. $SN_up = $_REQUEST [ 'txt_SN' ];
24. $CPU_up = $_REQUEST [ 'txt_CPU' ];
25. $OS_up = $_REQUEST [ 'txt_OS' ];
26.
27. echo $sqli = "UPDATE `masterpc` SET
28. `Computername` = '{$Computername_up}' ,
29. `Username` = '{$Username_up}' ,
30. Manufacturer` = '{$Manufacturer_up}' ,
31. `Model` = '{$Model_up}' ,
32. `SN` = '{$SN_up}' ,
33. `CPU` = '{$CPU_up}' ,
34. `OS` = '{$OS_up}'
35. WHERE
36. `Id` = '".$_REQUEST[' update_id '].' ";
37.
38. if (mysqli_query( $conn , $sqli )) {
39. echo "<script>alert('แก้ไขข้อมูลสำเร็จ...'); window.location ='index.php';</script>" ;
40. } else {
41. echo "Error: " . $sqli . "<br>" . mysqli_error( $conn );
42. }
43. mysqli_close( $conn );
44. }
45. ?>
|
 |
 |
 |
 |
Date :
2021-10-31 18:10:43 |
By :
TeeTs |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ตอบความคิดเห็นที่ : 32 เขียนโดย : mr.v เมื่อวันที่ 2021-10-31 18:39:46
รายละเอียดของการตอบ ::
แก้บรรทัด 36 แล้วครับ
response หน้าขาว ไม่มีแสดง error ครับ
ภาพ
Code (edit.php)
01. <?php
02. require_once ( '../../../database/connection.php' );
03.
04. if (isset( $_REQUEST [ 'update_id' ])) {
05. $sql = "SELECT * FROM `masterpc` WHERE `Id` = '" . $_REQUEST ['update_id ']."' ";
06. $result = $conn ->query( $sql );
07. while ( $row = $result ->fetch_array(MYSQLI_ASSOC)) {
08. $Computername = $row [ "Computername" ];
09. $Username = $row [ "Username" ];
10. $Manufacturer = $row [ "Manufacturer" ];
11. $Model = $row [ "Model" ];
12. $SN = $row [ "SN" ];
13. $CPU = $row [ "CPU" ];
14. $OS = $row [ "OS" ];
15. }
16. }
17.
18. if (isset( $_REQUEST [ 'btn_update' ])) {
19. $Computername_up = $_REQUEST [ 'txt_Computername' ];
20. $Username_up = $_REQUEST [ 'txt_Username' ];
21. $Manufacturer_up = $_REQUEST [ 'txt_Manufacturer' ];
22. $Model_up = $_REQUEST [ 'txt_Model' ];
23. $SN_up = $_REQUEST [ 'txt_SN' ];
24. $CPU_up = $_REQUEST [ 'txt_CPU' ];
25. $OS_up = $_REQUEST [ 'txt_OS' ];
26.
27. echo $sqli = "UPDATE `masterpc` SET
28. `Computername` = '{$Computername_up}' ,
29. `Username` = '{$Username_up}' ,
30. Manufacturer` = '{$Manufacturer_up}' ,
31. `Model` = '{$Model_up}' ,
32. `SN` = '{$SN_up}' ,
33. `CPU` = '{$CPU_up}' ,
34. `OS` = '{$OS_up}'
35. WHERE
36. `Id` = '".$_REQUEST[' update_id ']."' ";
37.
38. if (mysqli_query( $conn , $sqli )) {
39. echo "<script>alert('แก้ไขข้อมูลสำเร็จ...'); window.location ='index.php';</script>" ;
40. } else {
41. echo "Error: " . $sqli . "<br>" . mysqli_error( $conn );
42. }
43. mysqli_close( $conn );
44. }
45. ?>
Code (form-edit.php)
001. <?php
002.
003. require_once ( '../../../database/connection.php' );
004. require_once ( 'edit.php' );
005. ?>
006. <!DOCTYPE html>
007. <html lang= "en" >
008. <head>
009. <meta charset= "utf-8" >
010. <meta name= "viewport" content= "width=device-width, initial-scale=1" >
011. <title>แก้ไขข้อมูลทรัพย์สิน | CMS</title>
012. <link rel= "shortcut icon" type= "image/x-icon" href= "../../../assets/images/logo.png" >
013. <!-- stylesheet -->
015. <link rel= "stylesheet" href= "../../../plugins/fontawesome-free/css/all.min.css" >
016. <link rel= "stylesheet" href= "../../../plugins/sweetalert2-theme-bootstrap-4/bootstrap-4.min.css" >
017. <link rel= "stylesheet" href= "../../../assets/css/adminlte.min.css" >
018. <link rel= "stylesheet" href= "../../../assets/css/style.css" >
019. </head>
020. <body class = "hold-transition sidebar-mini" >
021. <div class = "wrapper" >
022. <?php include_once ( '../includes/sidebar.php' ) ?>
023. <div class = "content-wrapper pt-3" >
024. <!-- Main content -->
025. <div class = "content" >
026. <div class = "container-fluid" >
027. <div class = "row" >
028. <div class = "col-12" >
029. <div class = "card shadow" >
030. <div class = "card-header border-0 pt-4" >
031. <h4>
032. <i class = "fas fa-desktop" ></i>
033. แก้ไขข้อมูลผู้ดูแล
034. </h4>
035. <a href= "./" class = "btn btn-info my-3 " >
036. <i class = "fas fa-list" ></i>
037. กลับหน้าหลัก
038. </a>
039. </div>
040. <form action= "edit.php" method= "POST" >
041. <div class = "card-body" >
042. <div class = "row" >
043. <div class = "col-md-6 px-1 px-md-5" >
044.
045. <div class = "form-group" >
046. <label for = "Computername" >Computer Name</label>
047. <input type= "text" class = "form-control" name= "txt_Computername" id= "Computername" value= "<?php echo $Computername; ?>" required>
048. </div>
049. <div class = "form-group" >
050. <label for = "Username" >Username</label>
051. <input type= "text" class = "form-control" name= "txt_Username" id= "Username" value= "<?php echo $Username; ?>" required>
052. </div>
053. <div class = "form-group" >
054. <label for = "Manufacturer" >Manufacturer</label>
055. <input type= "text" class = "form-control" name= "txt_Manufacturer" id= "Manufacturer" value= "<?php echo $Manufacturer; ?>" required>
056. </div>
057. <div class = "form-group" >
058. <label for = "Model" >Model</label>
059. <input type= "text" class = "form-control" name= "txt_Model" id= "Model" value= "<?php echo $Model; ?>" required>
060. </div>
061.
062. </div>
063.
064. <div class = "col-md-6 px-1 px-md-5" >
065. <div class = "form-group" >
066. <label for = "Serialnumber" >Serial Number</label>
067. <input type= "text" class = "form-control" name= "txt_SN" id= "Serialnumber" value= "<?php echo $SN; ?>" required>
068. </div>
069.
070. <div class = "form-group" >
071. <label for = "CPU" >CPU</label>
072. <input type= "text" class = "form-control" name= "txt_CPU" id= "CPU" value= "<?php echo $CPU; ?>" required>
073. </div>
074.
075. <div class = "form-group" >
076. <label for = "OS" >OS</label>
077. <input type= "text" class = "form-control" name= "txt_OS" id= "OS" value= "<?php echo $OS; ?>" required>
078. </div>
079.
080. </div>
081. </div>
082. </div>
083. <div class = "card-footer" >
084. <input type= "hidden" name= "update_id" value= "<?php echo $_REQUEST['update_id']; ?>" >
085. <button type= "submit" name= "btn_update" class = "btn btn-primary btn-block mx-auto w-50" value= "update" >บันทึกข้อมูล</button>
086. </div>
087. </form>
088. </div>
089. </div>
090. </div>
091. </div>
092. </div>
093. </div>
094. <?php include_once ( '../includes/footer.php' ) ?>
095. </div>
096. <!-- SCRIPTS -->
097. <script src= "../../../plugins/jquery/jquery.min.js" ></script>
098. <script src= "../../../plugins/bootstrap/js/bootstrap.bundle.min.js" ></script>
099. <script src= "../../../plugins/sweetalert2/sweetalert2.min.js" ></script>
100. <script src= "../../../assets/js/adminlte.min.js" ></script>
101.
102.
103. </body>
104. </html>
***code no.14 แก้ตามคำแนะนำแล้ว เจอหน้าขาว ไม่มี error ใดๆ เดี๋ยวผมเสริมจาก no.25 เอาทีละ step ยังไม่ต้องสั่ง update, no.28 ป้องกัน sql injection ครับ***
|
 |
 |
 |
 |
Date :
2021-10-31 21:28:23 |
By :
TeeTs |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ตอบความคิดเห็นที่ : 34 เขียนโดย : mr.v เมื่อวันที่ 2021-10-31 21:35:11
รายละเอียดของการตอบ ::
ครับ ใส่ code ตามที่แนะนำแล้วนะครับ
response
Code (PHP)
01. REQUEST:
02. Array
03. (
04. [update_id] => 1
05. )
06. GET:
07. Array
08. (
09. [update_id] => 1
10. )
11. POST:
12. Array
13. (
14. )
Code (edit.php)
01. <?php
02. require_once ( '../../../database/connection.php' );
03.
04. if (isset( $_REQUEST [ 'update_id' ])) {
05. $sql = "SELECT * FROM `masterpc` WHERE `Id` = '" . $_REQUEST ['update_id ']."' ";
06. $result = $conn ->query( $sql );
07. while ( $row = $result ->fetch_array(MYSQLI_ASSOC)) {
08. $Computername = $row [ "Computername" ];
09. $Username = $row [ "Username" ];
10. $Manufacturer = $row [ "Manufacturer" ];
11. $Model = $row [ "Model" ];
12. $SN = $row [ "SN" ];
13. $CPU = $row [ "CPU" ];
14. $OS = $row [ "OS" ];
15. }
16. }
17.
18. echo 'REQUEST:<pre>' . print_r( $_REQUEST , true) . '</pre>' ;
19. echo 'GET:<pre>' . print_r( $_GET , true) . '</pre>' ;
20. echo 'POST:<pre>' . print_r( $_POST , true) . '</pre>' ;
21.
22. if (isset( $_REQUEST [ 'btn_update' ])) {
23. $Computername_up = $_REQUEST [ 'txt_Computername' ];
24. $Username_up = $_REQUEST [ 'txt_Username' ];
25. $Manufacturer_up = $_REQUEST [ 'txt_Manufacturer' ];
26. $Model_up = $_REQUEST [ 'txt_Model' ];
27. $SN_up = $_REQUEST [ 'txt_SN' ];
28. $CPU_up = $_REQUEST [ 'txt_CPU' ];
29. $OS_up = $_REQUEST [ 'txt_OS' ];
30.
31. echo $sqli = "UPDATE `masterpc` SET
32. `Computername` = '{$Computername_up}' ,
33. `Username` = '{$Username_up}' ,
34. Manufacturer` = '{$Manufacturer_up}' ,
35. `Model` = '{$Model_up}' ,
36. `SN` = '{$SN_up}' ,
37. `CPU` = '{$CPU_up}' ,
38. `OS` = '{$OS_up}'
39. WHERE
40. `Id` = '".$_REQUEST[' update_id ']."' ";
41.
42. if (mysqli_query( $conn , $sqli )) {
43. echo "<script>alert('แก้ไขข้อมูลสำเร็จ...'); window.location ='index.php';</script>" ;
44. } else {
45. echo "Error: " . $sqli . "<br>" . mysqli_error( $conn );
46. }
47. mysqli_close( $conn );
48. }
49. ?>
|
 |
 |
 |
 |
Date :
2021-10-31 21:44:50 |
By :
TeeTs |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ถ้าตัวฟอร์มเป็นแบบในคห. 33 จริงๆ ให้ลองปิด Javascript หรือเอาออกให้หมดก่อน แล้วทดลองกรอกข้อมูลกด submit ดูใหม่
|
 |
 |
 |
 |
Date :
2021-10-31 21:54:58 |
By :
mr.v |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ตอบความคิดเห็นที่ : 36 เขียนโดย : mr.v เมื่อวันที่ 2021-10-31 21:53:05
รายละเอียดของการตอบ ::
ขออภัยครับ ได้ข้อมูลตาม no.36 แล้วครับ
แก้ไขๆ หน้า index.php ผมใส่ a href ผิดครับ
Code (PHP)
01.
02. <a href= "edit.php?update_id=<?php echo $row[" Id "]; ?>" type= "button" class = "btn btn-danger " ><i class = "far fa-edit" ></i>
03. </a>
04.
05.
06. <a href= "form-edit.php?update_id=<?php echo $row[" Id "]; ?>" type= "button" class = "btn btn-danger " ><i class = "far fa-edit" ></i>
07. </a>
08.
09.
Code (index.php)
001. <?php
002.
003. require_once ( '../../../database/connection.php' );
004. ?>
005. <!DOCTYPE html>
006. <html lang= "en" >
007. <head>
008. <meta charset= "utf-8" >
009. <meta name= "viewport" content= "width=device-width, initial-scale=1" >
010. <title>มาสเตอร์ พีซี | CMS</title>
011. <link rel= "shortcut icon" type= "image/x-icon" href= "../../../assets/images/logo.png" >
012. <!-- stylesheet -->
014. <link rel= "stylesheet" href= "../../../plugins/fontawesome-free/css/all.min.css" >
015. <link rel= "stylesheet" href= "../../../plugins/sweetalert2-theme-bootstrap-4/bootstrap-4.min.css" >
016. <link rel= "stylesheet" href= "../../../assets/css/adminlte.min.css" >
017. <link rel= "stylesheet" href= "../../../assets/css/style.css" >
018. <!-- Datatables -->
019. <link rel= "stylesheet" href= "../../../plugins/datatables-bs4/css/dataTables.bootstrap4.min.css" >
020. <link rel= "stylesheet" href= "../../../plugins/datatables-responsive/css/responsive.bootstrap4.min.css" >
021. </head>
022. <body class = "hold-transition sidebar-mini" >
023. <div class = "wrapper" >
024. <?php include_once ( '../includes/sidebar.php' ) ?>
025. <div class = "content-wrapper pt-3" >
026. <!-- Main content -->
027. <div class = "content" >
028. <div class = "container-fluid" >
029. <div class = "row" >
030. <div class = "col-12" >
031. <div class = "card shadow" >
032. <div class = "card-header border-0 pt-4" >
033. <h4>
034. <i class = "fas fa-desktop" ></i>
035. มาสเตอร์ พีซี
036. </h4>
037. <a href= "form-create.php" class = "btn btn-primary mt-3" >
038. <i class = "fas fa-plus" ></i>
039. เพิ่มข้อมูล
040. </a>
041. </div>
042. <div class = "card-body" >
043. <!-- <div style= "overflow-x:auto;" > -->
044. <div class = "table-responsive" >
045. <table id= "myTable" class = "table table-striped table-hover" >
046.
047. <thead>
048. <tr>
049. <th>ID</th>
050. <th>Computername</th>
051. <th>Username</th>
052. <th>Manufacturer</th>
053. <th>Model</th>
054. <th>Serial Number</th>
055. <th>CPU</th>
056. <th>OS</th>
057. <th>Action</th>
058.
059. </tr>
060. </thead>
061.
062. <tbody>
063. <?php
064.
065. $sql = "SELECT * FROM masterpc" ;
066.
067. $result = $conn ->query( $sql );
068. while ( $row = $result ->fetch_array(MYSQLI_ASSOC)) {
069. ?>
070. <!-- class = "d-none text-left" style= "font-size:8pt;" -->
071. <tr>
072. <td class = "text-left" ><?php echo $row [ "Id" ]; ?></td>
073. <td class = "text-left" ><?php echo $row [ "Computername" ]; ?></td>
074. <td class = "text-left" ><?php echo $row [ "Username" ]; ?></td>
075. <td class = "text-left" ><?php echo $row [ "Manufacturer" ]; ?></td>
076. <td class = "text-left" ><?php echo $row [ "Model" ]; ?></td>
077. <td class = "text-left" ><?php echo $row [ "SN" ]; ?></td>
078. <td class = "text-left" ><?php echo $row [ "CPU" ]; ?></td>
079. <td class = "text-left" ><?php echo $row [ "OS" ]; ?></td>
080.
081. <td>
082. <div class = "btn-group" role= "group" aria-label= "Basic mixed styles example" >
083. <a href= "form-edit.php?update_id=<?php echo $row[" Id "]; ?>" type= "button" class = "btn btn-danger " ><i class = "far fa-edit" ></i>
084. </a>
085. <a href= "delete.php?delete_id=<?php echo $row[" Id "]; ?>" type= "button" class = "btn btn-warning text-white" ><i class = "fas fa-trash" ></i>
086. </a>
087. </div>
088. </td>
089. </tr>
090.
091. <?php } ?>
092. </tbody>
093. </table>
094. </div>
095. </div>
096. </div>
097. </div>
098. </div>
099. </div>
100. </div>
101. </div>
102. <?php include_once ( '../includes/footer.php' ) ?>
103. </div>
104.
105. <!-- scripts -->
106. <script src= "../../../plugins/jquery/jquery.min.js" ></script>
107. <script src= "../../../plugins/bootstrap/js/bootstrap.bundle.min.js" ></script>
108. <script src= "../../../plugins/sweetalert2/sweetalert2.min.js" ></script>
109. <script src= "../../../assets/js/adminlte.min.js" ></script>
110.
111. <!-- datatables -->
112. <script src= "..././../plugins/datatables/jquery.dataTables.min.js" ></script>
113. <script src= "../../../plugins/datatables-bs4/js/dataTables.bootstrap4.min.js" ></script>
114. <script src= "../../../plugins/datatables-responsive/js/dataTables.responsive.min.js" ></script>
115. <script src= "../../../plugins/datatables-responsive/js/responsive.bootstrap4.min.js" ></script>
116.
117.
118. </body>
119. </html>
Code (form-edit.php)
001. <?php
002.
003. require_once ( '../../../database/connection.php' );
004. require_once ( 'edit.php' );
005. ?>
006. <!DOCTYPE html>
007. <html lang= "en" >
008. <head>
009. <meta charset= "utf-8" >
010. <meta name= "viewport" content= "width=device-width, initial-scale=1" >
011. <title>แก้ไขข้อมูลทรัพย์สิน | CMS</title>
012. <link rel= "shortcut icon" type= "image/x-icon" href= "../../../assets/images/logo.png" >
013. <!-- stylesheet -->
015. <link rel= "stylesheet" href= "../../../plugins/fontawesome-free/css/all.min.css" >
016. <link rel= "stylesheet" href= "../../../plugins/sweetalert2-theme-bootstrap-4/bootstrap-4.min.css" >
017. <link rel= "stylesheet" href= "../../../assets/css/adminlte.min.css" >
018. <link rel= "stylesheet" href= "../../../assets/css/style.css" >
019. </head>
020. <body class = "hold-transition sidebar-mini" >
021. <div class = "wrapper" >
022. <?php include_once ( '../includes/sidebar.php' ) ?>
023. <div class = "content-wrapper pt-3" >
024. <!-- Main content -->
025. <div class = "content" >
026. <div class = "container-fluid" >
027. <div class = "row" >
028. <div class = "col-12" >
029. <div class = "card shadow" >
030. <div class = "card-header border-0 pt-4" >
031. <h4>
032. <i class = "fas fa-desktop" ></i>
033. แก้ไขข้อมูลผู้ดูแล
034. </h4>
035. <a href= "./" class = "btn btn-info my-3 " >
036. <i class = "fas fa-list" ></i>
037. กลับหน้าหลัก
038. </a>
039. </div>
040. <form action= "edit.php" method= "POST" >
041. <div class = "card-body" >
042. <div class = "row" >
043. <div class = "col-md-6 px-1 px-md-5" >
044.
045. <div class = "form-group" >
046. <label for = "Computername" >Computer Name</label>
047. <input type= "text" class = "form-control" name= "txt_Computername" id= "Computername" value= "<?php echo $Computername; ?>" required>
048. </div>
049. <div class = "form-group" >
050. <label for = "Username" >Username</label>
051. <input type= "text" class = "form-control" name= "txt_Username" id= "Username" value= "<?php echo $Username; ?>" required>
052. </div>
053. <div class = "form-group" >
054. <label for = "Manufacturer" >Manufacturer</label>
055. <input type= "text" class = "form-control" name= "txt_Manufacturer" id= "Manufacturer" value= "<?php echo $Manufacturer; ?>" required>
056. </div>
057. <div class = "form-group" >
058. <label for = "Model" >Model</label>
059. <input type= "text" class = "form-control" name= "txt_Model" id= "Model" value= "<?php echo $Model; ?>" required>
060. </div>
061.
062. </div>
063.
064. <div class = "col-md-6 px-1 px-md-5" >
065. <div class = "form-group" >
066. <label for = "Serialnumber" >Serial Number</label>
067. <input type= "text" class = "form-control" name= "txt_SN" id= "Serialnumber" value= "<?php echo $SN; ?>" required>
068. </div>
069.
070. <div class = "form-group" >
071. <label for = "CPU" >CPU</label>
072. <input type= "text" class = "form-control" name= "txt_CPU" id= "CPU" value= "<?php echo $CPU; ?>" required>
073. </div>
074.
075. <div class = "form-group" >
076. <label for = "OS" >OS</label>
077. <input type= "text" class = "form-control" name= "txt_OS" id= "OS" value= "<?php echo $OS; ?>" required>
078. </div>
079.
080. </div>
081. </div>
082. </div>
083. <div class = "card-footer" >
084. <input type= "hidden" name= "update_id" value= "<?php echo $_REQUEST['update_id']; ?>" >
085. <button type= "submit" name= "btn_update" class = "btn btn-primary btn-block mx-auto w-50" value= "update" >บันทึกข้อมูล</button>
086. </div>
087. </form>
088. </div>
089. </div>
090. </div>
091. </div>
092. </div>
093. </div>
094. <?php include_once ( '../includes/footer.php' ) ?>
095. </div>
096. <!-- SCRIPTS -->
097. <script src= "../../../plugins/jquery/jquery.min.js" ></script>
098. <script src= "../../../plugins/bootstrap/js/bootstrap.bundle.min.js" ></script>
099. <script src= "../../../plugins/sweetalert2/sweetalert2.min.js" ></script>
100. <script src= "../../../assets/js/adminlte.min.js" ></script>
101.
102. </body>
103. </html>
Code (edit.php)
01. <?php
02. require_once ( '../../../database/connection.php' );
03.
04. if (isset( $_REQUEST [ 'update_id' ])) {
05. $sql = "SELECT * FROM `masterpc` WHERE `Id` = '" . $_REQUEST ['update_id ']."' ";
06. $result = $conn ->query( $sql );
07. while ( $row = $result ->fetch_array(MYSQLI_ASSOC)) {
08. $Computername = $row [ "Computername" ];
09. $Username = $row [ "Username" ];
10. $Manufacturer = $row [ "Manufacturer" ];
11. $Model = $row [ "Model" ];
12. $SN = $row [ "SN" ];
13. $CPU = $row [ "CPU" ];
14. $OS = $row [ "OS" ];
15. }
16. }
17.
18. echo 'REQUEST:<pre>' . print_r( $_REQUEST , true) . '</pre>' ;
19. echo 'GET:<pre>' . print_r( $_GET , true) . '</pre>' ;
20. echo 'POST:<pre>' . print_r( $_POST , true) . '</pre>' ;
21.
22. if (isset( $_REQUEST [ 'btn_update' ])) {
23. $Computername_up = $_REQUEST [ 'txt_Computername' ];
24. $Username_up = $_REQUEST [ 'txt_Username' ];
25. $Manufacturer_up = $_REQUEST [ 'txt_Manufacturer' ];
26. $Model_up = $_REQUEST [ 'txt_Model' ];
27. $SN_up = $_REQUEST [ 'txt_SN' ];
28. $CPU_up = $_REQUEST [ 'txt_CPU' ];
29. $OS_up = $_REQUEST [ 'txt_OS' ];
30.
31. echo $sqli = "UPDATE `masterpc` SET
32. `Computername` = '{$Computername_up}' ,
33. `Username` = '{$Username_up}' ,
34. Manufacturer` = '{$Manufacturer_up}' ,
35. `Model` = '{$Model_up}' ,
36. `SN` = '{$SN_up}' ,
37. `CPU` = '{$CPU_up}' ,
38. `OS` = '{$OS_up}'
39. WHERE
40. `Id` = '".$_REQUEST[' update_id ']."' ";
41.
42. if (mysqli_query( $conn , $sqli )) {
43. echo "<script>alert('แก้ไขข้อมูลสำเร็จ...'); window.location ='index.php';</script>" ;
44. } else {
45. echo "Error: " . $sqli . "<br>" . mysqli_error( $conn );
46. }
47. mysqli_close( $conn );
48. }
49. ?>
Code (response)
01. REQUEST:
02. Array
03. (
04. [txt_Computername] => DESKTOP-817QJU0
05. [txt_Username] => DESKTOP-817QJU0ACER
06. [txt_Manufacturer] => Acer1
07. [txt_Model] => Aspire A315-21
08. [txt_SN] => NXGNVST007732194697600
09. [txt_CPU] => AMD A4-9120 RADEON R3, 4 COMPUTE CORES 2C+2G
10. [txt_OS] => Microsoft Windows 10 Pro
11. [update_id] => 1
12. [btn_update] => update
13. )
14. GET:
15. Array
16. (
17. )
18. POST:
19. Array
20. (
21. [txt_Computername] => DESKTOP-817QJU0
22. [txt_Username] => DESKTOP-817QJU0ACER
23. [txt_Manufacturer] => Acer1
24. [txt_Model] => Aspire A315-21
25. [txt_SN] => NXGNVST007732194697600
26. [txt_CPU] => AMD A4-9120 RADEON R3, 4 COMPUTE CORES 2C+2G
27. [txt_OS] => Microsoft Windows 10 Pro
28. [update_id] => 1
29. [btn_update] => update
30. )
31. UPDATE `masterpc` SET `Computername` = 'DESKTOP-817QJU0' , `Username` = 'DESKTOP-817QJU0ACER' , Manufacturer` = 'Acer1' , `Model` = 'Aspire A315-21' , `SN` = 'NXGNVST007732194697600' , `CPU` = 'AMD A4-9120 RADEON R3, 4 COMPUTE CORES 2C+2G' , `OS` = 'Microsoft Windows 10 Pro' WHERE `Id` = '1' Error: UPDATE `masterpc` SET `Computername` = 'DESKTOP-817QJU0' , `Username` = 'DESKTOP-817QJU0ACER' , Manufacturer` = 'Acer1' , `Model` = 'Aspire A315-21' , `SN` = 'NXGNVST007732194697600' , `CPU` = 'AMD A4-9120 RADEON R3, 4 COMPUTE CORES 2C+2G' , `OS` = 'Microsoft Windows 10 Pro' WHERE `Id` = '1'
32. You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '` = ' Acer1 ', `Model` = ' Aspire A315-21 ', `SN` = ' NXGNVS...' at line 4
***error in your SQL syntax หน้า response ผิด syntax อะไรหรอครับ ผมเช็คแล้ว ตามที่ no.14 แนะนำมาครับ***
|
ประวัติการแก้ไข 2021-10-31 22:27:07
 |
 |
 |
 |
Date :
2021-10-31 22:23:39 |
By :
TeeTs |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เปิดปิด backtick (`) ไม่ครบตรง Manufacturer
ตรวจให้ดีครับว่ามันจะต้องมี `Manufacturer` = 'xxx'
|
 |
 |
 |
 |
Date :
2021-10-31 22:41:56 |
By :
mr.v |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ตอบความคิดเห็นที่ : 40 เขียนโดย : TeeTs เมื่อวันที่ 2021-10-31 23:14:22
รายละเอียดของการตอบ ::
เห็นมั้ยว่าทำอย่างที่ผมบอกมันจะแก้ได้เร็ว และจะเสร็จไปนานแล้ว เพราะคนช่วยไม่ต้องเดาทุกครั้ง
1. ปุ่ม ` เรียกว่า back tick ถ้าเปลี่ยนภาษาโดยใช้ปุ่มนี้จะกดไม่ได้ ให้กด ALT+96 แต่ถ้าเปลี่ยนภาษาโดยใช้ปุ่มอื่น เช่น ALT+Shift หรือ [windows]+space แบบที่ผมใช้อยู่ จะกด backtick ได้เลย
2. backtick มีไว้คลุมชื่อฐานข้อมูล ชื่อตาราง ชื่อคอลัมน์ เพื่อบางกรณีชื่อคอลัมน์ไปตรงคำต้องห้าม ก็คลุมด้วย backtick มันจะทำงานได้ ไม่งั้นจะ error
ถ้าไม่มีอะไรตรงคำต้องห้ามจะไม่คลุม backtick ก็ได้ เช่น SELECT * FROM mytable จะได้เท่ากันกับ SELECT * FROM `mytable` แต่ผมจะแนะนำให้คลุมเพื่อแยกแยะให้ชัดเจนดูง่าย.
quote (') มีไว้เพื่อคลุมค่าที่เป็น string เช่น WHERE `column` = 'value'
ถ้าบางกรณีแบบนี้จะ error เช่น SELECT * FROM date เพราะคำว่า date เป็นคำสงวน 12 แต่ถ้าคลุมด้วย backtick มันจะทำงานได้ เช่น SELECT * FROM `date`
3. quote(') เอาไปคลุมชื่อตารางไม่ได้ ถ้าอยากลองก็ทดลองคำสั่งนั้นใน phpmyadmin แล้วดูว่ามัน error มั้ย? บางทีเรื่องอยากรู้อยากเห็นง่ายๆแบบนี้ทำได้ด้วยการทดลองเอาเอง และก็ควรหมั่นทดลองจะได้รู้แล้วสนุกด้วย.
Code (SQL)
1. SELECT * FROM 'rdb_posts'
Quote:You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ''rdb_posts''
4. คำตอบอยู่ใน 2. ส่วนการคลุมด้วยปีกกา (curly bracket) เป็นภาษาของ PHP ใช้กับการกำหนด string ด้วย double quote เช่น $string = "My {$name}"; แต่ถ้ากำหนด string ด้วย single quote จะใช้ไม่ได้ เช่น $string = 'My {$name}'; อยากรู้ไปทดลองเอาเอง หมั่นทดลองทดสอบ.
5. อธิบายไปแล้วใน 2. ดูตัวอย่างเพิ่มเติม
https://dev.mysql.com/doc/refman/8.0/en/identifiers.html
https://mariadb.com/kb/en/identifier-names/
|
 |
 |
 |
 |
Date :
2021-10-31 23:41:07 |
By :
mr.v |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ตอบความคิดเห็นที่ : 40 เขียนโดย : TeeTs เมื่อวันที่ 2021-10-31 23:14:22
รายละเอียดของการตอบ ::
backtick (`) หรือ เคาะเว้นวรรค หรือ ไม่เว้น
หรือ '{$Computername_up}' มันก็คือมาตรฐานการเขียนเช่นกัน
พอคุณเขียน javascript มันก็คล้ายๆกัน
มันเป็น Format, Code Style ในการเขียนให้อ่านง่ายเป็นระเบียบเรียบร้อย
ซึ่งมันเป็นข้อตกลงกันในทีม ส่วนใหญ่เรายึดตามมาตรฐานการเขียน (Code Standard)
ต่อจากนั้นคุณจะต้องรู้การ Refactoring, TDD
หรือรวมถึงการเลือกใช้ภาษาให้เหมาะกับงาน
ซึ่งต่อไปคุณต้องเรียน node, mongo, express, react, vue, angular, progressive web application, firebase etc,...
Code
เพราะนักพัฒนาไม่ได้สื่อสารแค่ภาษาเดียว
|
 |
 |
 |
 |
Date :
2021-11-01 08:10:46 |
By :
Guest |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ตอบความคิดเห็นที่ : 38 เขียนโดย : TeeTs เมื่อวันที่ 2021-10-31 22:23:39
รายละเอียดของการตอบ ::
... จากโค๊ดที่เห็น.....
flow control ไม่ถูกต้องนะครับ
ลองดูตัวอย่างนี้ดูครับ
Code (PHP)
01.
02. <?php
03. $include_update_php = 'update_input.php' ;
04. $include_form_edit = 'update_form.php' ;
05. if (isset( $_POST [ 'btn_update' ])){
06. include $update_php ;
07. header( 'location: link-file-ที่ต้องการ.php' );
08. } elseif (isset( $_GET [ 'update_id' ])){
09. include $include_form_edit ;
10. } else {
11. header( 'location: link-file-เมื่อการเข้ามาผิดปกติ.php' )
12. }
มันจะช่วยให้ทำงานเร็วขึ้น ไม่โหลดไฟล์ มาโดยไม่จำเป็น และการใช้ ตัวแปรในการ include ป้องกันการโหลดไฟล์ มาคอมไพล ล่วงหน้า
|
 |
 |
 |
 |
Date :
2021-11-01 13:25:34 |
By :
Chaidhanan |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ตอบความคิดเห็นที่ : 44 เขียนโดย : Chaidhanan เมื่อวันที่ 2021-11-01 13:25:34
รายละเอียดของการตอบ ::
code ส่วนนี้ทั้งหมดไว้บน form-edit.php ไหมครับ หรือไว้ในหน้า edit.php ครับ
ถ้าไว้หน้า form-edit.php ใช้แบบนี้ไหมครับ
Code (PHP)
01. <?php
02. require_once ( '../../../database/connection.php' );
03.
04.
05. $include_update_php = 'edit.php' ;
06. $include_form_edit = 'update_form.php' ;
07.
08. if (isset( $_POST [ 'btn_update' ])){
09. include $update_php ;
10. header( 'location: index.php' );
11. } elseif (isset( $_GET [ 'update_id' ])){
12. include $include_form_edit ;
13. } else {
14. header( 'location: index.php' )
15. }
16. ?>
|
 |
 |
 |
 |
Date :
2021-11-01 15:46:12 |
By :
TeeTs |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
หลังจากปรับใช้ code ครับ ขึ้นแบบนี้ครับ
ภาพที่ 1

Code (form-edit.php)
001. <?php
002.
003. require_once ( '../../../database/connection.php' );
004.
005.
006. $include_update_php = 'edit.php' ;
007. $include_form_edit = 'update_form.php' ;
008.
009. if (isset( $_POST [ 'btn_update' ])){
010. include $include_update_php ;
011. header( 'location: index.php' );
012. } elseif (isset( $_GET [ 'update_id' ])){
013. include $include_form_edit ;
014. } else {
015. header( 'location: index.php' );
016. }
017. ?>
018. <!DOCTYPE html>
019. <html lang= "en" >
020. <head>
021. <meta charset= "utf-8" >
022. <meta name= "viewport" content= "width=device-width, initial-scale=1" >
023. <title>แก้ไขข้อมูลทรัพย์สิน | CMS</title>
024. <link rel= "shortcut icon" type= "image/x-icon" href= "../../../assets/images/logo.png" >
025. <!-- stylesheet -->
027. <link rel= "stylesheet" href= "../../../plugins/fontawesome-free/css/all.min.css" >
028. <link rel= "stylesheet" href= "../../../plugins/sweetalert2-theme-bootstrap-4/bootstrap-4.min.css" >
029. <link rel= "stylesheet" href= "../../../assets/css/adminlte.min.css" >
030. <link rel= "stylesheet" href= "../../../assets/css/style.css" >
031. </head>
032. <body class = "hold-transition sidebar-mini" >
033. <div class = "wrapper" >
034. <?php include_once ( '../includes/sidebar.php' ) ?>
035. <div class = "content-wrapper pt-3" >
036. <!-- Main content -->
037. <div class = "content" >
038. <div class = "container-fluid" >
039. <div class = "row" >
040. <div class = "col-12" >
041. <div class = "card shadow" >
042. <div class = "card-header border-0 pt-4" >
043. <h4>
044. <i class = "fas fa-desktop" ></i>
045. แก้ไขข้อมูลผู้ดูแล
046. </h4>
047. <a href= "./" class = "btn btn-info my-3 " >
048. <i class = "fas fa-list" ></i>
049. กลับหน้าหลัก
050. </a>
051. </div>
052. <form action= "edit.php" method= "POST" >
053. <div class = "card-body" >
054. <div class = "row" >
055. <div class = "col-md-6 px-1 px-md-5" >
056.
057. <div class = "form-group" >
058. <label for = "Computername" >Computer Name</label>
059. <input type= "text" class = "form-control" name= "txt_Computername" id= "Computername" value= "<?php echo $Computername; ?>" required>
060. </div>
061. <div class = "form-group" >
062. <label for = "Username" >Username</label>
063. <input type= "text" class = "form-control" name= "txt_Username" id= "Username" value= "<?php echo $Username; ?>" required>
064. </div>
065. <div class = "form-group" >
066. <label for = "Manufacturer" >Manufacturer</label>
067. <input type= "text" class = "form-control" name= "txt_Manufacturer" id= "Manufacturer" value= "<?php echo $Manufacturer; ?>" required>
068. </div>
069. <div class = "form-group" >
070. <label for = "Model" >Model</label>
071. <input type= "text" class = "form-control" name= "txt_Model" id= "Model" value= "<?php echo $Model; ?>" required>
072. </div>
073.
074. </div>
075.
076. <div class = "col-md-6 px-1 px-md-5" >
077. <div class = "form-group" >
078. <label for = "Serialnumber" >Serial Number</label>
079. <input type= "text" class = "form-control" name= "txt_SN" id= "Serialnumber" value= "<?php echo $SN; ?>" required>
080. </div>
081.
082. <div class = "form-group" >
083. <label for = "CPU" >CPU</label>
084. <input type= "text" class = "form-control" name= "txt_CPU" id= "CPU" value= "<?php echo $CPU; ?>" required>
085. </div>
086.
087. <div class = "form-group" >
088. <label for = "OS" >OS</label>
089. <input type= "text" class = "form-control" name= "txt_OS" id= "OS" value= "<?php echo $OS; ?>" required>
090. </div>
091.
092. </div>
093. </div>
094. </div>
095. <div class = "card-footer" >
096. <!-- <input type= "hidden" name= "update_id" value= "<?php echo row[" Id "]; ?>" >
097. <input type= "hidden" name= "update_id" value= "<?php echo $Id; ?>" > -->
098. <input type= "hidden" name= "update_id" value= "<?php echo $_REQUEST['update_id']; ?>" >
099. <button type= "submit" name= "btn_update" class = "btn btn-primary btn-block mx-auto w-50" value= "update" >บันทึกข้อมูล</button>
100. </div>
101. </form>
102. </div>
103. </div>
104. </div>
105. </div>
106. </div>
107. </div>
108. <?php include_once ( '../includes/footer.php' ) ?>
109. </div>
110. <!-- SCRIPTS -->
111. <script src= "../../../plugins/jquery/jquery.min.js" ></script>
112. <script src= "../../../plugins/bootstrap/js/bootstrap.bundle.min.js" ></script>
113. <script src= "../../../plugins/sweetalert2/sweetalert2.min.js" ></script>
114. <script src= "../../../assets/js/adminlte.min.js" ></script>
115.
116.
117.
118. </body>
119. </html>
|
 |
 |
 |
 |
Date :
2021-11-01 15:53:43 |
By :
TeeTs |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เจอปัญหา ในหน้า pages manager
พึ่งเปิดไปช่วงเช้าครับ
link นี้ครับ : https://www.thaicreate.com/php/forum/136451.html
ส่วนในโพสต์ที่ปรึกษานี้ เป็น pages masterpc ครับ ที่พึ่งแก้ได้ไปเมื่อวานครับ
|
 |
 |
 |
 |
Date :
2021-11-01 16:04:34 |
By :
TeeTs |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (PHP)
01. <?php
02.
03. require_once ( '../../../database/connection.php' );
04. $include_update_php = 'edit.php' ;
05. $include_form_edit = 'up_form.php' ;
06.
07. if (isset( $_POST [ 'btn_update' ])){
08. include $include_update_php ;
09. header( 'location: index.php' );
10.
11. } elseif (isset( $_GET [ 'update_id' ])){
12.
13. include $include_form_edit ;
14. } else {
15. header( 'location: index.php' )
16. }
17.
Code (PHP)
Code (PHP)
1. <?php
2.
3. <!doctype html>
4. <html>
5. ....
6. ...
แยกไฟล์ แบบนี้ครับ
ปล. อันนี้เป็น แค่วิธีการ แยก / จัดสรรไฟล์ เป็นพื้นฐาน
จะได้ประโยชน์มากๆ เมื่อไฟล์มีขนาดใหญ่ กว่า 4096 byte( ขนาด 1 เซคเม้นต์ในการอ่าน harddisk แต่ละครั้ง ของ ระบบ buffer ntfs มาตรฐาน)
ถ้าไฟล์ ใหญ่พอที่สามารถอ่านได้ในครั้งเดียว ก็จะเร็วขึ้น
|
ประวัติการแก้ไข 2021-11-01 20:50:09
 |
 |
 |
 |
Date :
2021-11-01 20:32:18 |
By :
Chaidhanan |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณครับ
|
 |
 |
 |
 |
Date :
2021-11-02 17:59:51 |
By :
TeeTs |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|