ช่วยเหลือหน่อยค่ะ Upload รูปภาพ Dreamweaver แล้ว Error ค่ะ
มี Error แจ้งเตือนว่า Column 'Trip_img' cannot be null ค่ะ ช่วยหน่อยค่ะ
Code (PHP)
<?php require_once('../Connections/connection.php'); ?>
<?php include("dw-upload.inc.php"); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO trip (Trip_Name, Trip_Lati, Trip_Longti, Trip_Categories, Trip_Deatail, Trip_Note, Trip_img, User_ID) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['Trip_Name'], "text"),
GetSQLValueString($_POST['Trip_Lati'], "double"),
GetSQLValueString($_POST['Trip_Longti'], "double"),
GetSQLValueString($_POST['Trip_Categories'], "text"),
GetSQLValueString($_POST['Trip_Deatail'], "text"),
GetSQLValueString($_POST['Trip_Note'], "text"),
GetSQLValueString(dwUpload($_FILES['img']), "text"),
GetSQLValueString($_POST['User_ID'], "int"));
mysql_select_db($database_connection, $connection);
$Result1 = mysql_query($insertSQL, $connection) or die(mysql_error());
$insertGoTo = "../mng_trip.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
$colname_Recordset1 = "-1";
if (isset($_GET['User_ID'])) {
$colname_Recordset1 = $_GET['User_ID'];
}
mysql_select_db($database_connection, $connection);
$query_Recordset1 = sprintf("SELECT * FROM trip WHERE User_ID = %s", GetSQLValueString($colname_Recordset1, "int"));
$Recordset1 = mysql_query($query_Recordset1, $connection) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
?>
ไฟล์ dw-upload ค่ะ
Code (PHP)
<?php
function dwUpload($file,$path="./img-products/"){
if(@copy($file['tmp_name'],$path.$file['name'])){
@chmod($path.$file,0777);
return $file['name'];
}else{
return false;
}
}
?>
Tag : MySQL, HTML/CSS
Date :
2016-01-25 16:23:54
By :
narslins_mc
View :
2602
Reply :
10
jj
ประวัติการแก้ไข 2016-01-25 16:47:01
Date :
2016-01-25 16:42:14
By :
mm
ใน phpMyAdmin ตอนสร้าง Table ไม่ได้กำหนด Column ชื่อว่า Trip_img ให้เป็น Allow Null ครับ
Date :
2016-01-25 16:51:45
By :
mr.win
ได้ทำตามที่ผมแนะนำแล้วหรือยังครับ
Date :
2016-01-26 09:21:50
By :
mr.win
Date :
2016-01-26 12:21:53
By :
555
ในส่วน หน้า insert.php
Code (PHP)
<?php require_once('../Connections/mycon.php'); ?>
<?php include("dw-upload.inc.php"); ?>
<?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO forklift (Code, Maker, Model, Serial, Mast, Power, Gear, Attachment, `Year`, `Hour`, Photo) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['Code'], "text"),
GetSQLValueString($_POST['Maker'], "text"),
GetSQLValueString($_POST['Model'], "text"),
GetSQLValueString($_POST['Serial'], "text"),
GetSQLValueString($_POST['Mast'], "text"),
GetSQLValueString($_POST['Power'], "text"),
GetSQLValueString($_POST['Gear'], "text"),
GetSQLValueString($_POST['Attachment'], "text"),
GetSQLValueString($_POST['Year'], "text"),
GetSQLValueString($_POST['Hour'], "text"),
GetSQLValueString(dwUpload($_FILES['Photo']), "text"));
mysql_select_db($database_mycon, $mycon);
$Result1 = mysql_query($insertSQL, $mycon) or die(mysql_error());
$insertGoTo = "Backoffice.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
?>
ในส่วน dw-upload.inc.php
Code (PHP)
<?php
function dwUpload($file,$path="./Forklifts/"){
if(@copy($file['tmp_name'],$path.$file['name'])){
@chmod($path.$file,0777);
return $file['name'];
}else{
return false;
}
}
?>
Error :Column 'Photo' cannot be null
ทำตามด้านบนแล้วครับได้
Code (PHP)
<?php
function dwUpload($file,$path="./Forklifts/"){
if(copy($file['tmp_name'],$path.$file['name'])){
chmod($path.$file,0777);
return $file['name'];
}else{
return false;
}
}
?>
Error : Warning: copy(): Filename cannot be empty in C:\xampp\htdocs\Matehan\dw-upload.inc.php on line 3
Column 'Photo' cannot be null
ใน phpmyadmin ของเดิม
12 Photo varchar(20) No None
แก้เป็น
12 Photo varchar(20) Yes NULL
ปัญหาที่พบคือ ข้อมูลทุกอย่างมาครบ ยกเว้น ค่าที่เก็บชื่อไฟล์ และรูปภาพที่เลือกไม่เข้าFoder ที่กำหนดไว้ครับ
id Code Maker Model Serial Mast Power Gear Attachment Year Hour Photo
13 1587 MITSUBISHI FD25NT CF18C-15489 V3 DEISEL AT MOVER 2016 0 NULL
Date :
2016-06-07 11:16:56
By :
MIKE
เป็นแบบเดียวกันเรยครับ ช่วยหน่อยครับ
Date :
2016-07-29 23:13:43
By :
wiwat
Load balance : Server 04