|
 |
|
php บันทึกข้อมูลเข้า db แต่ไม่มีไฟล์ในโฟลเดอร์ครับ |
|
 |
|
|
 |
 |
|
บันทึกข้อมูลเข้า data base นะครับ ชื่อรูปก็บันทึกแต่ว่ารูปไม่มาอยู่ในโฟลเดอร์ที่ตั้งไว้ครับครับช่วยดูหน่อยครับ
Code
<form id="topup" name="change" action="topup_insert.php" method="post" enctype="multipart/form-data" class="input-group">
<div class="container">
<label>จำนวนเงิน :</label>
<input type="radio" name="money_topup" value="50">
<label>
50 coin = 50 บาท
</label>
<input type="radio" name="money_topup" value="100">
<label>
120 coin = 100 บาท
</label>
<input type="radio" name="money_topup" value="500">
<label>
600 coin = 500 บาท
</label>
<input type="radio" name="money_topup" value="1000">
<label>
1200 coin = 1000 บาท
</label>
</div>
<div class="container">
<div class="space">
<label>โอนมาที่บัญชี :</label>
<input type="radio" name="bankname_topup" value="kbank">
<label>
kbank
</label>
<input type="radio" name="bankname_topup" value="ktb">
<label>
ktb
</label>
</div>
</div>
<div class="container">
<div class="space2">
<label>วันที่และเวลาที่โอน :</label>
<input type="date" name="date_topup">
<input type="time" name="time_topup">
</div>
</div>
<div class="container">
<div class="space3">
<label>อัปโหลด :</label>
<input type="file" name="slip_topup"/>
</div>
</div>
<button name="submit" type="submit" class="submit-button">ยืนยัน</button>
Code (PHP)
<?php
session_start();
include 'connect.php';
$money_topup = $_POST['money_topup'];
$bankname_topup = $_POST['bankname_topup'];
$date_topup = $_POST['date_topup'];
$time_topup = $_POST['time_topup'];
$slip_topup = $_POST['slip_topup'];
$ext = pathinfo(basename($_FILES['slip_topup']['name']), PATHINFO_EXTENSION);
$new_image_name = 'img_'.uniqid().".".$ext;
$image_path = "imagg/";
$upload_path = $image_path.$new_image_name;
//uploading
$success = move_uploaded_file($_FILE['slip_topup']['tmp_name'],$upload_path);
if($success == FALSE){
echo "<script type='text/javascript'>";
echo "alert('unsuccess');";
echo "window.location ='topup.php'; ";
echo "</script>";
}
$slip_topup = $new_image_name;
$query = "INSERT INTO topup(money_topup,bankname_topup,date_topup,time_topup,slip_topup) VALUES ('$money_topup','$bankname_topup','$date_topup','$time_topup','$slip_topup')";
$result = mysqli_query($conn,$query);
if($result){
echo "<script type='text/javascript'>";
echo "alert('success');";
echo "window.location ='content.php'; ";
echo "</script>";
}
?>
Tag : PHP, MySQL

|
ประวัติการแก้ไข 2020-08-19 15:23:38
|
 |
 |
 |
 |
Date :
2020-08-19 15:21:06 |
By :
tnp2398 |
View :
631 |
Reply :
8 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
print_r($_FILES);exit();
$_FILES
$_FILES
$_FILES
$_FILES
$_FILES
$_FILES
|
ประวัติการแก้ไข 2020-08-19 22:42:29 2020-08-19 22:42:43 2020-08-19 22:43:00 2020-08-19 22:44:28
 |
 |
 |
 |
Date :
2020-08-19 22:41:48 |
By :
mr.v |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ถ้า move_uploaded_file() ไม่คืนค่าเป็น FALSE
ที่เหลือก็คือ path ถ้าจะให้ช่วยดู ต้องบอก project/directory structure
อย่างน้อย ที่อยู่ไฟล์ topup_insert.php กับโฟลเดอร์ imagg
ไม่งั้นก็ต้องงมเอง เพราะไม่มีใครรู้ด้วย
ศึกษา Relative and absolute paths
https://phpdelusions.net/articles/paths
|
ประวัติการแก้ไข 2020-08-20 13:55:27
 |
 |
 |
 |
Date :
2020-08-20 13:51:56 |
By :
PhrayaDev |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ตอนนี้มีปัญหาใหม่แล้วครับถ้าจะเก็บค่าจาก dropdown ซึ่งเราสามารถระบุค่านั้นเองได้ต้องเขียนประมาณไหนครับ
Code (PHP)
<?php
$q = "SELECT * FROM content_type";
$result = mysqli_query($conn,$q);
?>
<select class="text-center" name="name_type" id="name_type" required>
<option value="">เลือกประเภท</option>
<?php
while ($row = mysqli_fetch_array($result,MYSQLI_NUM)) {
echo "<option value='$row[0]'>$row[1]</option>";
}
?>
<option value="4">ระบุเอง</option>
<?php
if($value = "4"){
$sql = "INSERT INTO content_type (name_type) VALUES ($name_type)";
}
?>
</select><br />
<div id="box">
<input type="text" class="text-center" name="txt_box" id="txt_box" placeholder="ระบุประเภท"/>
</div>
<textarea type="text" class="text-center" name="synopsis" style="width:450px;" id="synopsis"
maxlength="300" placeholder="กรุณากรอก เรื่องย่อ *300 ตัวอักษร" required></textarea>
<div class="container">
<div class="space3">
<label>อัปโหลดหน้าปก :</label>
<input type="file" name="cover_img"/>
</div>
</div>
<button name="submit" type="submit" class="submit-button">ยืนยัน</button>
Code (PHP)
<?php
session_start();
include 'connect.php';
$name_type = $_POST['name_type'];
$content_name = $_POST['content_name'];
$cover_img = $_POST['cover_img'];
$synopsis = $_POST['synopsis'];
$sql2 = "INSERT INTO content_type(name_type) VALUES ('$name_type')";
$result1 = mysqli_query($conn,$sql2);
$sql1 = "INSERT INTO content(content_name,cover_img,synopsis) VALUES ('$content_name','$cover_img','$synopsis')";
$result2 = mysqli_query($conn,$sql2);
if($result1 && $result2){
echo "<script type='text/javascript'>";
echo "alert('เพิ่มสำเร็จ');";
echo "window.location ='content.php'; ";
echo "</script>";
}
?>
|
ประวัติการแก้ไข 2020-08-20 19:49:20 2020-08-20 21:18:01
 |
 |
 |
 |
Date :
2020-08-20 19:45:29 |
By :
tnp2398 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ใช้ JS onclick/onchange + AJAX
ตัวอย่างการเช็คสถานะของ select option
<select id="myOptions">
<option value='option1'>Gateway 1</option>
<option value='option2'>Gateway 2</option>
<option value='option3'>Gateway 3</option>
</select>
Code (JavaScript)
$('#myOptions').change(function() {
var val = $('option[value="option3"]:selected', this).text();
val ? alert(val) : $();
});
จากนั้นทำ ajax(ใน event ที่ชอบ) เพิ่ม name_type ใน db
ตัวอย่างการใช้ ajax() method
Code (JavaScript)
$.ajax({
method: "POST",
url: "some.php",
data: { nametype: $('nametype_selector').val() }
})
.done(function( msg ) {
alert( "Data Saved: " + msg );
});
https://api.jquery.com/jquery.ajax/
https://www.w3schools.com/jquery/ajax_ajax.asp (แบบเดิม)
เรียนรู้ด้วยการปฏิบัติ...ลองประกอบร่างดูครับ
แถม http://programmerblog.net/jquery-ajax-get-example-php-mysql/
|
ประวัติการแก้ไข 2020-08-20 22:47:11 2020-08-20 22:53:06
 |
 |
 |
 |
Date :
2020-08-20 22:42:43 |
By :
PhrayaDev |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 03
|