|
 |
|
EROR !! โค๊ด รูปภาพ ในบทเรียน ของพี่วินอ่ะ หนูลองทำแร้วรูปไม่ขึ้นอ่ะ |
|
 |
|
|
 |
 |
|
หนูลองเอาของที่พี่วินให้ไว้ในบทเรียน ไปลองทำ แป๊ะเรย
Table
CREATE TABLE `files` (
`FilesID` int(4) NOT NULL auto_increment,
`Name` varchar(100) NOT NULL,
`FilesName` varchar(100) NOT NULL,
PRIMARY KEY (`FilesID`)
) ENGINE=MyISAM AUTO_INCREMENT=1 ;
Code (PageUploadToMySQL1.php)
<html>
<head>
<title>ThaiCreate.Com Tutorial</title>
</head>
<body>
<form name="form1" method="post" action="PageUploadToMySQL2.php" enctype="multipart/form-data">
Name : <input type="text" name="txtName"><br>
Picture : <input type="file" name="filUpload"><br>
<input name="btnSubmit" type="submit" value="Submit">
</form>
</body>
</html>
Code (PageUploadToMySQL2.php)
<html>
<head>
<title>ThaiCreate.Com Tutorial</title>
</head>
<body>
<?
if(move_uploaded_file($_FILES["filUpload"]["tmp_name"],"myfile/".$_FILES["filUpload"]["name"]))
{
echo "Copy/Upload Complete<br>";
//*** Insert Record ***//
$objConnect = mysql_connect("localhost","root","root") or die("Error Connect to Database");
$objDB = mysql_select_db("mydatabase");
$strSQL = "INSERT INTO files ";
$strSQL .="(Name,FilesName) VALUES ('".$_POST["txtName"]."','".$_FILES["filUpload"]["name"]."')";
$objQuery = mysql_query($strSQL);
}
?>
<a href="PageUploadToMySQL3.php">View files</a>
</body>
</html>
Code (PageUploadToMySQL3.php)
<html>
<head>
<title>ThaiCreate.Com Tutorial</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head>
<body>
<?
$objConnect = mysql_connect("localhost","root","root") or die("Error Connect to Database");
$objDB = mysql_select_db("mydatabase");
$strSQL = "SELECT * FROM files";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
?>
<table width="340" border="1">
<tr>
<th width="50"> <div align="center">Files ID </div></th>
<th width="150"> <div align="center">Picture</div></th>
<th width="150"> <div align="center">Name</div></th>
<th width="150"> <div align="center">Edit</div></th>
</tr>
<?
while($objResult = mysql_fetch_array($objQuery))
{
?>
<tr>
<td><div align="center"><?=$objResult["FilesID"];?></div></td>
<td><center><img src="myfile/<?=$objResult["FilesName"];?>"></center></td>
<td><center><?=$objResult["Name"];?></center></td>
<td><center><a href="PageUploadToMySQL4.php?FilesID=<?=$objResult["FilesID"];?>">Edit</a></center></td>
</tr>
<?
}
?>
</table>
<?
mysql_close($objConnect);
?>
</body>
</html>
Code (PageUploadToMySQL4.php)
<html>
<head>
<title>ThaiCreate.Com Tutorial</title>
</head>
<body>
<?
$objConnect = mysql_connect("localhost","root","root") or die("Error Connect to Database");
$objDB = mysql_select_db("mydatabase");
$strSQL = "SELECT * FROM files WHERE FilesID = '".$_GET["FilesID"]."' ";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
$objResult = mysql_fetch_array($objQuery);
?>
<form name="form1" method="post" action="PageUploadToMySQL5.php?FilesID=<?=$_GET["FilesID"];?>" enctype="multipart/form-data">
Edit Picture :<br>
Name : <input type="text" name="txtName" value="<?=$objResult["Name"];?>"><br>
<img src="myfile/<?=$objResult["FilesName"];?>"><br>
Picture : <input type="file" name="filUpload"><br>
<input type="hidden" name="hdnOldFile" value="<?=$objResult["FilesName"];?>">
<input name="btnSubmit" type="submit" value="Submit">
</form>
</body>
</html>
PageUploadToMySQL5.php
<html>
<head>
<title>ThaiCreate.Com Tutorial</title>
</head>
<body>
<?
//*** Update Record ***//
$objConnect = mysql_connect("localhost","root","root") or die("Error Connect to Database");
$objDB = mysql_select_db("mydatabase");
$strSQL = "UPDATE files ";
$strSQL .=" SET NAME = '".$_POST["txtName"]."' WHERE FilesID = '".$_GET["FilesID"]."' ";
$objQuery = mysql_query($strSQL);
if($_FILES["filUpload"]["name"] != "")
{
if(move_uploaded_file($_FILES["filUpload"]["tmp_name"],"myfile/".$_FILES["filUpload"]["name"]))
{
//*** Delete Old File ***//
@unlink("myfile/".$_POST["hdnOldFile"]);
//*** Update New File ***//
$strSQL = "UPDATE files ";
$strSQL .=" SET FilesName = '".$_FILES["filUpload"]["name"]."' WHERE FilesID = '".$_GET["FilesID"]."' ";
$objQuery = mysql_query($strSQL);
echo "Copy/Upload Complete<br>";
}
}
?>
<a href="PageUploadToMySQL3.php">View files</a>
</body>
</html>
แต่ทำไมพอรัน รูปมันไม่ขึ้นอ่ะคะ แต่ขึ้นเป็นกากบาทสีแดง แทน ค่ะ
Tag : PHP

|
|
 |
 |
 |
 |
Date :
2012-07-28 12:17:45 |
By :
นักศึกษา |
View :
1130 |
Reply :
3 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ในฐานข้อมูลมีข้อมูลหรือรูปภาพหรือเปล่าครับ ตรวจสอบ Path ด้วยครับ
|
 |
 |
 |
 |
Date :
2012-07-28 13:33:50 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ปัญหานี้
1. ในเบสมีชื่อไฟล์รูปหรือป่าว
2. ที่อยู่ของโฟล์เดอร์รูปถูกต้องหรือป่าว
|
 |
 |
 |
 |
Date :
2012-07-28 15:04:59 |
By :
บังเอิญผ่านมาเห็น |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code ในบทความผ่านการ Test มาแล้วทุกตัวน่ะครับ 
|
 |
 |
 |
 |
Date :
2012-07-29 07:33:49 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 01
|