|
|
|
เราทำหน้าสำหรับอัพข้อมูลค่ะ แต่เรารูปไม่เข้าไม่เข้าฐานข้อมูล ช่วยเราหน่อยนะค่ะ |
|
|
|
|
|
|
|
เราทำหน้าสำหรับอัพข้อมูลค่ะ แต่รูปไม่เข้า
ช่วยหน่อยค่ะ
evemt.php
Code (PHP)
<?php require_once('Connections/work.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;
}
}
mysql_select_db($database_work, $work);
$query_Recordset1 = "SELECT FilesName FROM working";
$Recordset1 = mysql_query($query_Recordset1, $work) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
error_reporting(0);
session_start();
?>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Main Working</title>
<style type="text/css">
body {
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
background-image: url(img/web.jpg);
}
</style>
</head>
<body>
<form id="form1" name="form1" method="post" action="save.php?id_work=<?php echo $_GET["id_work"];?>">
<?
require_once("comfig.php");
if(!isset($_SESSION['id_username']))
{
echo "<script>alert('กรุณาลงชื่อเข้าระบบ'); window.location='index.php';</script>";
exit();
}
$objConnect = mysql_connect("localhost","root","1234") or die("Error Connect to Database");
$objDB = mysql_select_db("graphic");
if(!empty($_GET["id_work"] )){
$strSQL = "SELECT * FROM working WHERE id_work = '".$_GET["id_work"]."' ";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
$objResult = mysql_fetch_array($objQuery);
}else{
$id_work = '';
}
?>
<table width="1033" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td height="29" colspan="5" align="center" valign="baseline"><img src="img/Untitled-1-01.png" width="1024" height="300"></td>
</tr>
<tr>
<td height="19" valign="top" bgcolor="#FFFFFF"> </td>
<td valign="top" bgcolor="#FFFFFF"> </td>
<td valign="top" bgcolor="#FFFFFF"> </td>
<td width="283" valign="top" bgcolor="#FFFFFF"> </td>
<td width="193" valign="top" bgcolor="#FFFFFF"> </td>
</tr>
<tr>
<td width="128" height="27" valign="top" bgcolor="#FFFFFF"> ชื่องาน</td>
<td width="285" valign="top" bgcolor="#FFFFFF"><label for="name_job"></label>
<input name="name_job" type="text" id="name_job" value="<?php echo $objResult["name_job"];?>" size="40" /></td>
<td width="144" valign="top" bgcolor="#FFFFFF">ประเภทงาน</td>
<td colspan="2" valign="top" bgcolor="#FFFFFF"><select name="category" id="category">
<option><?php echo $objResult["id_category"];?></option>
<option value="C01">Sticker</option>
<option value="C02">Vinly</option>
<option value="C03">Brochure</option>
</select>
<label for="category2"></label> <label for="textfield"></label></td>
</tr>
<tr>
<td height="27" valign="top" bgcolor="#FFFFFF"> วันที่รับงาน</td>
<td valign="top" bgcolor="#FFFFFF"><label for="s_date"></label>
<input name="s_date" type="date" id="s_date" value="<?php echo $objResult["start_job"];?>" /></td>
<td valign="top" bgcolor="#FFFFFF">วันที่คาดว่าเสร็จ</td>
<td colspan="2" valign="top" bgcolor="#FFFFFF"><label for="e_date"></label>
<input name="e_date" type="date" id="e_date" value="<?php echo $objResult["expect_job"];?>" /></td>
</tr>
<tr>
<td height="28" valign="top" bgcolor="#FFFFFF"> วันที่เสร็จ</td>
<td colspan="4" valign="top" bgcolor="#FFFFFF"><label for="c_date"></label>
<input name="c_date" type="date" id="c_date" value="<?php echo $objResult["complete_job"];?>" /></td>
</tr>
<tr>
<td height="27" valign="top" bgcolor="#FFFFFF"> ชื่อลูกค้า</td>
<td colspan="4" valign="top" bgcolor="#FFFFFF"><input name="customer" type="text" id="customer" value="<?php echo $objResult["customer_name"];?>" size="40" /></td>
</tr>
<tr>
<td height="27" valign="top" bgcolor="#FFFFFF"> ชื่อผู้สังงาน</td>
<td colspan="4" valign="top" bgcolor="#FFFFFF"><input name="name" type="text" id="name" value="<?php echo $objResult["command"];?>" size="40" /></td>
</tr>
<tr>
<td height="28" valign="top" bgcolor="#FFFFFF"> สถานะ</td>
<td colspan="4" valign="top" bgcolor="#FFFFFF"><select name="status" id="status">
<option selected="selected" ><?php echo $objResult["status"];?></option>
<?php
$strSQL = "SELECT * FROM status ORDER BY id_status ASC";
$objQuery = mysql_query($strSQL);
while($objResuut = mysql_fetch_array($objQuery))
{
?>
<option value="<?php echo $objResuut["id_status"];?>"><?php echo $objResuut["id_status"]." - ".$objResuut["status"];?></option>
<?php
}
?>
</select></td>
</tr>
<tr>
<td height="137" valign="top" bgcolor="#FFFFFF"> รายระเอียด</td>
<td colspan="4" valign="top" bgcolor="#FFFFFF"><p>
<textarea name="detail" cols="100" rows="8" id="detail"><?php echo $objResult["detail"];?></textarea>
</p></td>
</tr>
<tr>
<td height="131" valign="top" bgcolor="#FFFFFF"> แนบไฟล์</td>
<td height="131" colspan="4" valign="top" bgcolor="#FFFFFF"><br>
<img src="myfile/<?php echo $objResult["FilesName"];?>" height="150"><br>
<input type="file" name="filUpload">
<br>
<input type="hidden" name="hdnOldFile" value="<?php echo $objResult["FilesName"];?>"></td>
</tr>
<tr>
<td height="28" colspan="5" align="center" valign="top" bgcolor="#FFFFFF"><label for="id"></label>
<input name="id" type="text" id="id" value="<?php echo $objResult["id_work"];?>" size="5" /></td>
</tr>
<tr>
<td height="32" colspan="5" align="center" valign="top" bgcolor="#FFFFFF"><input type="submit" name="button" id="button" value="Submit" />
<input type="reset" name="button2" id="button2" value="Reset" /></td>
</tr>
</table>
</form>
</body>
</html><?php
mysql_free_result($Recordset1);
?>
save.php
Code (PHP)
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Main Working</title>
<?php
$objConnect = mysql_connect("localhost","root","1234") or die("Error Connect to Database");
$objDB = mysql_select_db("graphic");
if (($_POST['id'])){
$objDB = mysql_select_db("graphic");
$strSQL = "UPDATE working SET ";
$strSQL .="name_job = '".$_POST["name_job"]."' ";
$strSQL .=",id_category = '".$_POST["category"]."' ";
$strSQL .=",start_job = '".$_POST["s_date"]."' ";
$strSQL .=",expect_job = '".$_POST["e_date"]."' ";
$strSQL .=",complete_job = '".$_POST["c_date"]."' ";
$strSQL .=",command = '".$_POST["name"]."' ";
$strSQL .=",customer_name = '".$_POST["customer"]."' ";
$strSQL .=",status = '".$_POST["status"]."' ";
$strSQL .=",detail = '".$_POST["detail"]."' ";
$strSQL .="WHERE id_work = '".$_GET["id_work"]."' ";
$objQuery = mysql_query($strSQL);
if($_FILES["filUpload"]["name"] != "")
{
if(move_uploaded_file($_FILES["filUpload"]["tmp_name"],"myfile/".$_FILES["filUpload"]["name"]))
{
//*** ลบไฟล์เก่า ***//
@unlink("myfile/".$_POST["hdnOldFile"]);
//*** อัพไฟล์ใหม่ ***//
$strSQL = "UPDATE working ";
$strSQL .=" SET FilesName = '".$_FILES["filUpload"]["name"]."' WHERE id_work = '".$_GET["id_work"]."' ";
$objQuery = mysql_query($strSQL);
}
}
}
else {
$objDB = mysql_select_db("graphic");
$strSQL = "INSERT INTO working SET ";
$strSQL .="name_job = '".$_POST["name_job"]."' ";
$strSQL .=",id_category = '".$_POST["category"]."' ";
$strSQL .=",start_job = '".$_POST["s_date"]."' ";
$strSQL .=",expect_job = '".$_POST["e_date"]."' ";
$strSQL .=",complete_job = '".$_POST["c_date"]."' ";
$strSQL .=",command = '".$_POST["name"]."' ";
$strSQL .=",customer_name = '".$_POST["customer"]."' ";
$strSQL .=",status = '".$_POST["status"]."' ";
$strSQL .=",detail = '".$_POST["detail"]."' ";
$strSQL .=",FilesName = '".$_FILES["filUpload"]["name"]."' ";
$objQuery = mysql_query($strSQL)or die(mysql_error());
mysql_close($objConnect);
}
?>
<script type="text/javascript"> window.location="mainworking.php" </script>
Tag : PHP, MySQL
|
|
|
|
|
|
Date :
2015-10-13 13:55:01 |
By :
Narybee |
View :
1005 |
Reply :
20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ก็ไม่เขียนโค้ดอัพโหลด ของเงื่อนไข INSERT มันก็เลยไม่เข้าจร้าา
|
|
|
|
|
Date :
2015-10-13 14:48:32 |
By :
CasanovaKung |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ยังไงหรอค่ะ ใช่แบบนี้ไหม
Code (PHP)
$objDB = mysql_select_db("graphic");
$strSQL = "INSERT INTO working SET ";
$strSQL .="name_job = '".$_POST["name_job"]."' ";
$strSQL .=",id_category = '".$_POST["category"]."' ";
$strSQL .=",start_job = '".$_POST["s_date"]."' ";
$strSQL .=",expect_job = '".$_POST["e_date"]."' ";
$strSQL .=",complete_job = '".$_POST["c_date"]."' ";
$strSQL .=",command = '".$_POST["name"]."' ";
$strSQL .=",customer_name = '".$_POST["customer"]."' ";
$strSQL .=",status = '".$_POST["status"]."' ";
$strSQL .=",detail = '".$_POST["detail"]."' ";
$objQuery = mysql_query($strSQL)or die(mysql_error());
if(move_uploaded_file($_FILES["filUpload"]["tmp_name"],"myfile/".$_FILES["filUpload"]["name"]))
{
echo "Copy/Upload Complete<br>";
//*** Insert Record ***//
$objDB = mysql_select_db("graphic");
$strSQL = "INSERT INTO working ";
$strSQL .="(FilesName) VALUES ('".$_FILES["filUpload"]["name"]."')";
$objQuery = mysql_query($strSQL);
}
mysql_close($objConnect);
|
|
|
|
|
Date :
2015-10-13 15:32:11 |
By :
Narybee |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
insert ครั้งแรกจำเป็นต้องอัพรูปเสมอหรือป่าว?
ถ้าไม่ใช่ประมาณนี้นะ
Code (PHP)
$objDB = mysql_select_db("graphic");
$strSQL = "INSERT INTO working SET ";
$strSQL .="name_job = '".$_POST["name_job"]."' ";
$strSQL .=",id_category = '".$_POST["category"]."' ";
$strSQL .=",start_job = '".$_POST["s_date"]."' ";
$strSQL .=",expect_job = '".$_POST["e_date"]."' ";
$strSQL .=",complete_job = '".$_POST["c_date"]."' ";
$strSQL .=",command = '".$_POST["name"]."' ";
$strSQL .=",customer_name = '".$_POST["customer"]."' ";
$strSQL .=",status = '".$_POST["status"]."' ";
$strSQL .=",detail = '".$_POST["detail"]."' ";
//$objQuery = mysql_query($strSQL)or die(mysql_error());
if(move_uploaded_file($_FILES["filUpload"]["tmp_name"],"myfile/".$_FILES["filUpload"]["name"]))
{
echo "Copy/Upload Complete<br>";
//*** Insert Record ***//
//$objDB = mysql_select_db("graphic");
//$strSQL = "INSERT INTO working ";
//$strSQL .="(FilesName) VALUES ('".$_FILES["filUpload"]["name"]."')";
//$objQuery = mysql_query($strSQL);
$strSQL .=",FilesName = '".$_FILES["filUpload"]["name"]."' ";
}
$objQuery = mysql_query($strSQL)or die(mysql_error());
mysql_close($objConnect);
ถ้าไม่ใช่ MySQL syntax insert แบบนี้อาจใช้ไม่ได้นะ
|
|
|
|
|
Date :
2015-10-13 16:26:50 |
By :
CasanovaKung |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ไม่จำเป็นค่ะ
บางที่ก็ไม่ใส่
|
ประวัติการแก้ไข 2015-10-13 17:04:32
|
|
|
|
Date :
2015-10-13 17:03:57 |
By :
Narybee |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
แจ้ง or die() ว่าอย่างไร?
|
|
|
|
|
Date :
2015-10-14 10:40:51 |
By :
CasanovaKung |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
อะลองดูครับ
save.php
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Main Working</title>
<?php
$objConnect = mysql_connect("localhost","root","1234") or die("Error Connect to Database");
$objDB = mysql_select_db("graphic");
#----- Check Upload file -----#
if($_FILES["filUpload"]["name"] != "")
{
if(move_uploaded_file($_FILES["filUpload"]["tmp_name"],"myfile/".$_FILES["filUpload"]["name"]))
{
$fileName = $_FILES["filUpload"]["name"];
} else {
$fileName = '';
}
}
if (($_POST['id'])){
$objDB = mysql_select_db("graphic");
$strSQL = "UPDATE working SET ";
$strSQL .="name_job = '".$_POST["name_job"]."' ";
$strSQL .=",id_category = '".$_POST["category"]."' ";
$strSQL .=",start_job = '".$_POST["s_date"]."' ";
$strSQL .=",expect_job = '".$_POST["e_date"]."' ";
$strSQL .=",complete_job = '".$_POST["c_date"]."' ";
$strSQL .=",command = '".$_POST["name"]."' ";
$strSQL .=",customer_name = '".$_POST["customer"]."' ";
$strSQL .=",status = '".$_POST["status"]."' ";
$strSQL .=",detail = '".$_POST["detail"]."' ";
if(!empty($fileNmae)){
//*** ลบไฟล์เก่า ***//
@unlink("myfile/".$_POST["hdnOldFile"]);
//*** อัพไฟล์ใหม่ ***//
$strSQL .= ",FilesName = '$fileNmae' ";
}
$strSQL .="WHERE id_work = '".$_GET["id_work"]."' ";
$objQuery = mysql_query($strSQL);
}
else {
$objDB = mysql_select_db("graphic");
$strSQL = "INSERT INTO working SET ";
$strSQL .="name_job = '".$_POST["name_job"]."' ";
$strSQL .=",id_category = '".$_POST["category"]."' ";
$strSQL .=",start_job = '".$_POST["s_date"]."' ";
$strSQL .=",expect_job = '".$_POST["e_date"]."' ";
$strSQL .=",complete_job = '".$_POST["c_date"]."' ";
$strSQL .=",command = '".$_POST["name"]."' ";
$strSQL .=",customer_name = '".$_POST["customer"]."' ";
$strSQL .=",status = '".$_POST["status"]."' ";
$strSQL .=",detail = '".$_POST["detail"]."' ";
$strSQL .=",FilesName = '$fileNmae' ";
$objQuery = mysql_query($strSQL)or die(mysql_error());
mysql_close($objConnect);
}
?>
<script type="text/javascript"> window.location="mainworking.php" </script>
|
ประวัติการแก้ไข 2015-10-14 11:02:46
|
|
|
|
Date :
2015-10-14 11:01:53 |
By :
arm8957 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ไม่แจ้งค่ะ มันบันทึกข้อมูลแล้ว แต่ รูปไม่บันทึก ค่ะ ไม่มีแจ้ง error ด้วย
เราใช้ BLOB ในการเก็บข้อมูลรูปภาพนะค่ะ ไม่รู้เป็นเพราะตัวนี้หรือเปล่า เพราะเห็นคนอื่นใช้เป็น varchar กัน
|
ประวัติการแก้ไข 2015-10-14 11:14:36
|
|
|
|
Date :
2015-10-14 11:10:42 |
By :
Narybee |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
เราเองก็เปลียนเป็น Varchar แล้วค่ะตอนนี้ก็ใช้เป็น Varchar อยู่แต่ก็ยังไม่สามารถเก็บข้อมูลของรูปได้เลยค่ะ
|
ประวัติการแก้ไข 2015-10-14 11:32:36 2015-10-14 11:33:57
|
|
|
|
Date :
2015-10-14 11:30:04 |
By :
Narybee |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
แก้แล้วค่ะ แต่ก็ยังไม่เข้าค่ะ T_T
|
|
|
|
|
Date :
2015-10-14 11:49:47 |
By :
Narybee |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
รูปอัพโหลดได้รึยัง? (ดูในโฟล์เดอร์ myfile) ถ้าอัพรูปได้แล้ว ให้ลองเช็คคำสั่ง sql ดูว่าถูกต้องหรือไม่? ดังนี้
Code (PHP)
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Main Working</title>
<?php
$objConnect = mysql_connect("localhost","root","1234") or die("Error Connect to Database");
$objDB = mysql_select_db("graphic");
#----- Check Upload file -----#
if($_FILES["filUpload"]["name"] != "")
{
if(move_uploaded_file($_FILES["filUpload"]["tmp_name"],"myfile/".$_FILES["filUpload"]["name"]))
{
$fileName = $_FILES["filUpload"]["name"];
} else {
$fileName = '';
}
}
if (($_POST['id'])){
$objDB = mysql_select_db("graphic");
$strSQL = "UPDATE working SET ";
$strSQL .="name_job = '".$_POST["name_job"]."' ";
$strSQL .=",id_category = '".$_POST["category"]."' ";
$strSQL .=",start_job = '".$_POST["s_date"]."' ";
$strSQL .=",expect_job = '".$_POST["e_date"]."' ";
$strSQL .=",complete_job = '".$_POST["c_date"]."' ";
$strSQL .=",command = '".$_POST["name"]."' ";
$strSQL .=",customer_name = '".$_POST["customer"]."' ";
$strSQL .=",status = '".$_POST["status"]."' ";
$strSQL .=",detail = '".$_POST["detail"]."' ";
if(!empty($fileNmae)){
//*** ลบไฟล์เก่า ***//
@unlink("myfile/".$_POST["hdnOldFile"]);
//*** อัพไฟล์ใหม่ ***//
$strSQL .= ",FilesName = '$fileNmae' ";
}
$strSQL .="WHERE id_work = '".$_GET["id_work"]."' ";
echo $strSQL;
$objQuery = mysql_query($strSQL);
}
else {
$objDB = mysql_select_db("graphic");
$strSQL = "INSERT INTO working SET ";
$strSQL .="name_job = '".$_POST["name_job"]."' ";
$strSQL .=",id_category = '".$_POST["category"]."' ";
$strSQL .=",start_job = '".$_POST["s_date"]."' ";
$strSQL .=",expect_job = '".$_POST["e_date"]."' ";
$strSQL .=",complete_job = '".$_POST["c_date"]."' ";
$strSQL .=",command = '".$_POST["name"]."' ";
$strSQL .=",customer_name = '".$_POST["customer"]."' ";
$strSQL .=",status = '".$_POST["status"]."' ";
$strSQL .=",detail = '".$_POST["detail"]."' ";
$strSQL .=",FilesName = '$fileNmae' ";
echo $strSQL;
$objQuery = mysql_query($strSQL)or die(mysql_error());
mysql_close($objConnect);
}
?>
<script type="text/javascript"> window.location="mainworking.php" </script>
|
|
|
|
|
Date :
2015-10-14 11:56:03 |
By :
arm8957 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
รูปเข้า myfile แล้วค่ะ แต่ ข้อมูลยังไม่เข้า DB ลองเชคแล้วค่ะ ก็ไม่ผิดนะ ลองแก้เป็นแบบของคุณ ไม่มีอะไรเกิดขึ้นเลย
|
|
|
|
|
Date :
2015-10-14 13:01:48 |
By :
Narybee |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
อย่าบอกว่าใช้ $fileNmae นะครับ
|
|
|
|
|
Date :
2015-10-14 13:11:32 |
By :
CasanovaKung |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
มันก็ต้องแจ้ง ว่าไม่พบตัวแปร $fileNmae นะ
เป็น เพราะนี่หรือป่าว?
Code (PHP)
040. error_reporting(0);
|
|
|
|
|
Date :
2015-10-14 13:57:49 |
By :
CasanovaKung |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ขอบคุณทุท่านมาก ๆ ๆ เลยค่ะ
|
|
|
|
|
Date :
2015-10-14 15:04:44 |
By :
Narybee |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 02
|