|
|
|
ทำไม php insert ข้อมูลลง database สองรอบ (เมื่อใช้ browser chrome 12 ใช้ ie ff ไม่เป็นไร) |
|
|
|
|
|
|
|
ช่วยเทสหน่อยครับ
http://442.im/webboard/frm_create.php
นี่คือไฟล์รับข้อมูลลง DB
add_quiz.php
Code (PHP)
<?php
session_start();
include("common/connect.php");
include("common/fncAll.php");
echo '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
$quiz_topic= $_POST['quiz_topic'];
$quiz_message = $_POST['quiz_message'];
$quiz_name = $_POST['quiz_name'];
$quiz_email = $_POST['quiz_email'];
$quiz_date = date('Y-m-d h:i:s');
$quiz_attach =$_FILES['quiz_attach']; //array
/*
echo $quiz_attach[name] ;
echo $quiz_attach[type] ;
echo $quiz_attach[tmp_name] ;
echo $quiz_attach[size] ;
*/
//print_r($quiz_attach ) ; exit();
/////////////////// get extention for attach file //////////////////////
$extention = explode( '/' , $quiz_attach[type] ); //array
//print_r($extention) ;
//exit();
if ($quiz_topic =='' || $quiz_message =='' || $quiz_name =='' || $quiz_email =='' || $quiz_date =='' ){
echo '<script>alert("คุณกรอกข้อมูลไม่ครบ");</script>';
echo '<script>history.back()</script>';
}
if($quiz_attach[size]>0 ){
if ( $quiz_attach[type] == "image/jpeg" || $quiz_attach[type] == "image/pjpeg" || $quiz_attach[type] == "image/gif" ){
$name_from_time=time(); // create new name for photo upload
$newname = $name_from_time.".".$extention[1];
// echo $newname; exit();
move_uploaded_file($quiz_attach[tmp_name], "attach/$newname" );
$sql = "insert into tb_quiz ( id_quiz , quiz_topic , quiz_message , quiz_name , quiz_email , quiz_attach, quiz_date, quiz_view, quiz_reply ) " ;
$sql .= "value ( '' , '$quiz_topic ', '$quiz_message', '$quiz_name', '$quiz_email', '$newname', '$quiz_date','' ,'' ) " ;
echo $sql ; exit();
$result =mysql_query($sql, $link);
//print_r($result);
if (! ($result) ){
echo '<script> alert("ไม่สามารถเพิ่มกระทู้ได้ครับ");</script>';
echo '<script> history.back();</script> ';
}else{
echo '<script> alert("เพิ่มกระทู้แล้วครับ");</script>';
echo '<script>window.location="index.php"</script> ';
}
}else{
echo '<script>alert ("ภาพที่อัพโหลดต้องเป็นนามสกุล JPG หรือ GIF เท่านั้น")</script>';
echo '<script>history.back()</script>';
}
}else{
$sql = "insert into tb_quiz ( id_quiz , quiz_topic , quiz_message , quiz_name , quiz_email , quiz_attach, quiz_date, quiz_view, quiz_reply ) " ;
$sql .= "value ( '' , '$quiz_topic ', '$quiz_message', '$quiz_name', '$quiz_email', '', '$quiz_date','' ,'' ) " ;
//echo $sql ;
//exit();
$result =mysql_query($sql, $link);
//print_r($result);
if (! ($result) ){
echo '<script> alert("ไม่สามารถเพิ่มกระทู้ได้ครับ");</script>';
echo '<script> history.back();</script> ';
}else{
echo '<script> alert("เพิ่มกระทู้แล้วครับ");</script>';
echo '<script>window.location="index.php"</script> ';
}
}
?>
Tag : PHP, MySQL
|
ประวัติการแก้ไข 2011-10-06 15:08:07 2011-10-06 15:28:32
|
|
|
|
|
Date :
2011-10-06 14:54:36 |
By :
likhi1 |
View :
9235 |
Reply :
1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 03
|