ขอ Code php เมื่อกด Ok ใน alert แล้วกรณีกรอกข้อมูลไม่ครบ ข้อมูลที่ใส่ไปไม่หาย
ถาม-ตอบ แนะนำไอเดียว โค้ดตัวอย่าง แนวทาง วิธีแก้ปัญหา ขอ Code php เมื่อกด Ok ใน alert แล้วกรณีกรอกข้อมูลไม่ครบ ข้อมูลที่ใส่ไปไม่หาย
ขอ Code php เมื่อกด Ok ใน alert แล้วกรณีกรอกข้อมูลไม่ครบ ข้อมูลที่ใส่ไปไม่หาย
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 | <?php ob_start(); session_start(); $id = $_SESSION [ "id" ]; $no_id = $_SESSION [ 'no_id' ]; $eid = $_GET [ "edit_id" ]; include ( "connect.php" ); if ( $id == "" ){ echo "<script language='javascript' type='text/javascript' > alert('กรุณาล็อกอินก่อนเข้าใช้งาน');</script>" ; echo '<meta http-equiv= "refresh" content="0; url=index.php"/>' ; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" > <head> <title>IT Technologies</title> <meta http-equiv= "Content-Type" content= "text/html; charset=utf-8" /> <link href= "style.css" rel= "stylesheet" type= "text/css" /> <script src= "js/cufon-yui.js" type= "text/javascript" ></script> <script src= "js/cufon-replace.js" type= "text/javascript" ></script> <script src= "js/Myriad_Pro_300.font.js" type= "text/javascript" ></script> <!--[ if lt IE 7]> <script type= "text/javascript" src= "js/ie_png.js" ></script> <script type= "text/javascript" >ie_png.fix( '.png, #header .row-2 ul li a, #content, .list li' );</script> <![ endif ]--> </head> <body id= "page1" > <div class = "tail-top" > <div class = "tail-bottom" > <div class = "body-bg" > <!-- HEADER --> <div id= "header" > <div class = "row-1" ><a href= "#" ><img src= "images/logo.gif" alt= "" /></a> <div class = "fright" ></div> </div> <div class = "row-2" > <ul> <li class = "m1" ><a href= "index3.php" >หน้าแรก</a></li> <li class = "m2" ><a href= "manage_user.php" >จัดการผู้เรียน</a></li> <li class = "m3" ><a href= "manage_content.php" >จัดการเนื้อหา</a></li> <li class = "m4" ><a href= "manage_test.php" >จัดการแบบฝึกหัด</a></li> <li class = "m5" ><a href= "manage_exam.php" class = "active" >จัดการข้อสอบ</a></li> </ul></div> <div class = "row-3" > </div> </div> <!-- CONTENT --> <div id= "content" > <h2 align= "center" > </h2> <h2 align= "center" > </h2> <h2 align= "center" > </h2> <h2 align= "center" >จัดการข้อสอบ</h2> <div class = "tail-yot" > <div class = "wrapper" > <div class = "col-01" > <div class = "indent" > <div class = "indent1" > <table width= "110%" border= "0" align= "center" > <tr> <td colspan= "2" bgcolor= "#66B2FF" > <h2 align= "center" ><strong>แก้ไขข้อสอบ</strong></h2> </td> </tr> <tr> <form action = "check_edit_exam.php?edit_no=<?php echo $eid; ?>" method= "post" > <?php $sql1 = "SELECT * FROM exam WHERE exam_id='$eid' " ; $qry1 =mysqli_query( $objConnect , $sql1 ); $result1 = mysqli_fetch_array( $qry1 ); $quest = $result1 [ 'exam_question' ]; $choice1 = $result1 [ 'exam_choice1' ]; $choice2 = $result1 [ 'exam_choice2' ]; $choice3 = $result1 [ 'exam_choice3' ]; $choice4 = $result1 [ 'exam_choice4' ]; $ans = $result1 [ 'exam_answer' ]; $level = $result1 [ 'exam_level' ]; ?> <tr> <td height= "43" ><strong>คำถาม</strong></td> <td><label> <textarea name= "question" cols= "70" rows= "4" ><?php echo "$quest" ?></textarea> </label> </td> </tr> <tr> <td height= "43" ><strong>ตัวเลือกที่ 1 </strong></td> <td><label> <input type= "text" name= "choice1" value= "<?php echo $choice1 ?>" /> </label> </td> </tr> <tr> <td height= "43" ><strong>ตัวเลือกที่ 2 </strong></td> <td><label> <input type= "text" name= "choice2" value= "<?php echo $choice2 ?> " /> </label> </td> </tr> <tr> <td height= "43" ><strong>ตัวเลือกที่ 3 </strong></td> <td><label> <input type= "text" name= "choice3" value= "<?php echo $choice3 ?> " /> </label> </td> </tr> <tr> <td height= "43" ><strong>ตัวเลือกที่ 4 </strong></td> <td><label> <input type= "text" name= "choice4" value= "<?php echo $choice4 ?> " /> </label> </td> </tr> <tr> <td height= "43" ><strong>ตัวเลือกที่ถูกต้อง</strong></td> <td> <select name= "answer" > <option>--เลือกข้อ--</option> <option value= "1" >ตัวเลือกที่ 1</option> <option value= "2" >ตัวเลือกที่ 2</option> <option value= "3" >ตัวเลือกที่ 3</option> <option value= "4" >ตัวเลือกที่ 4</option> </select> </span></td> </tr> <tr> <td height= "43" ><strong>ระดับข้อสอบ</strong></td> <td> <select name= "level" > <option>--เลือกระดับ--</option> <option value= "ง่าย" <?php if ( $level == 'ง่าย' ){ echo "selected" ;} ?>>ง่าย</option> <option value= "ปานกลาง" <?php if ( $level == 'ปานกลาง' ){ echo "selected" ;} ?>>ปานกลาง</option> <option value= "ยาก" <?php if ( $level == 'ยาก' ){ echo "selected" ;} ?>>ยาก</option> </select> </span></td> </tr> <tr> <td height= "64" colspan= "2" bgcolor= "#66B2FF" align= "center" ><label> <input type= "submit" name= "Submit2" value= "บันทึก" /> </label> </td> </tr> </table> <p> </p> </form></td> </tr> </table> </div> </ul> </div> </div> </div> </div> </div> </div> <!-- FOOTER --> <div id= "footer" > <div class = "indent" > </div> </div> </div> </div> </div> <script type= "text/javascript" > Cufon.now(); </script> </body> </html> |

คำแนะนำ และการใช้งาน
สมาชิก กรุณา ล็อกอินเข้าระบบ เพื่อตั้งคำถามใหม่ หรือ ตอบคำถาม สมาชิกใหม่ สมัครสมาชิกได้ที่ สมัครสมาชิก
- ถาม-ตอบ กรุณา ล็อกอินเข้าระบบ
ความคิดเห็นที่
1
กรณีส่งค่าในหน้าเดียวกันและ ไม่มีการ redirect หน้าไปหน้าอื่น หรือไม่ได้เป็นการโหลดหน้าเพจที่ส่งค่าใหม่
ให้ใช้วิธีเช็คค่าที่มีการส่งข้อมูล ว่ามีค่าเดิมหรือไม่ถ้ามีก็ใช้ค่าเดิมแสดง ถ้าไม่มีก็เป็นค่าว่าง
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | // input , textarea <input name= "data1" type= "text" value= "<?=(isset($_POST['data1']))?$_POST['data1']:" "?>" /> <textarea name= "data2" ><?=(isset( $_POST [ 'data2' ]))? $_POST [ 'data2' ]: "" ?></textarea> // checkbox , radio <input type= "radio" name= "data3" value= "3" <?=(isset( $_POST [ 'data3' ]) && $_POST [ 'data3' ]==3)? " checked" : "" ?> /> <input name= "data4" type= "checkbox" value= "4" <?=(isset( $_POST [ 'data4' ]) && $_POST [ 'data4' ]==4)? " checked" : "" ?> /> // <select> <select name= "answer" > <option>--เลือกข้อ--</option> <option value= "1" <?=(isset( $_POST [ 'answer' ]) && $_POST [ 'answer' ]==1)? " selected" : "" ?>>ตัวเลือกที่ 1</option> <option value= "2" <?=(isset( $_POST [ 'answer' ]) && $_POST [ 'answer' ]==2)? " selected" : "" ?>>ตัวเลือกที่ 2</option> </select> |
แต่กรณีมีการส่งค่าไปใช้ใช้งานหน้าอื่นและ redirect กลับมามาหน้าฟอร์มกรอกข้อมูล ให้ลองใช้ตัวแปร session หรือ cookie
ในการเก็บค่า หรือใช้ localStorage ของ html5 ก็ได้ ดูความคิดเห็นนี้เป็นแนวทาง

ขอบคุณทุกการสนับสนุน
![]()