 |
|
ส่งค่า ID เพื่อ update รูปลงฐานข้อมูลไม่ไปครับ แต่move รูปภาพได้ปกติ เหลือแค่updateรูปลงฐานข้อมูล
ID เป็นค่าว่างเลยครับ ผมพลาดส่วนไหนไปรบกวนหน่อยครับ

หน้าแก้ไขข้อมูล
Code (PHP)
<html>
<head>
<title>ThaiCreate.Com PHP & MySQL Tutorial</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<?php
$objConnect = mysql_connect("localhost","root","root") or die("Error Connect to Database");
$objDB = mysql_select_db("sspgcom_db");
mysql_query("SET NAMES UTF8");
$strSQL = "SELECT * FROM student WHERE class='3' AND room='3' ORDER BY id ASC";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
?>
<form name="frmMain" method="post" action="all1.php" enctype="multipart/form-data">
<table width="70%" border="1">
<tr>
<th width="40%"> <div align="center">ชื่อ</div></th>
<th width="15%"> <div align="center">รหัสนักเรียน</div></th>
<th width="15%"> <div align="center">ชั้น</div></th>
<th width="15%"> <div align="center">ห้อง </div></th>
<th width="20%"> <div align="center">Used </div></th>
</tr>
<?php
$i =0;
while($objResult = mysql_fetch_array($objQuery))
{
$i = $i + 1;
?>
<tr>
<td><?php echo $objResult["name"];?></td>
<td><?php echo $objResult["username"];?></td>
<td><?php echo $objResult["class"];?></div></td>
<td><?php echo $objResult["room"];?></td>
<td align="center"><input type="file" name="filUpload<?php echo $i;?>" size="20" value="<?php echo $objResult["pic"];?>"></td>
</tr>
<?php
}
?>
</table>
<input type="submit" name="submit" value="submit">
<input type="hidden" name="hdnLine" value="<?php echo $i;?>">
</form>
<?php
mysql_close($objConnect);
?>
</body>
</html>
หน้าupdateข้อมูล
Code (PHP)
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<?php
$objConnect = mysql_connect("localhost","root","root") or die("Error Connect to Database");
$objDB = mysql_select_db("sspgcom_db");
mysql_query("SET NAMES UTF8");
for($i=1;$i<=$_POST["hdnLine"];$i++)
{
$myImage = imagecreatefromjpeg($_FILES["filUpload".$i]["tmp_name"]);
$myCopyright = imagecreatefromjpeg('myfile/logo.jpg');
move_uploaded_file($_FILES["filUpload".$i]["tmp_name"],"myfile/".$_FILES["filUpload".$i]["name"]);
$destWidth = imagesx($myImage);
$destHeight = imagesy($myImage);
$srcWidth = imagesx($myCopyright);
$srcHeight = imagesy($myCopyright);
$destX = ($destWidth - $srcWidth) / 2;
$destY = ($destHeight - $srcHeight) / 5;
$white = imagecolorexact($myCopyright, 64, 64,64);
imagecolortransparent($myCopyright, $white);
imagecopymerge($myImage, $myCopyright, $destX, $destY, 0, 0, $srcWidth, $srcHeight, 20);
imagejpeg($myImage,"myfile/".$_FILES["filUpload".$i]["name"]);
imagedestroy($myImage);
imagedestroy($myCopyright);
$strSQL = "UPDATE student SET ";
$strSQL .=" pic = '".$_FILES["filUpload".$i]["name"]."'";
$strSQL .="WHERE id = '".$_POST["hdnid$i"]."' ";
$objQuery = mysql_query($strSQL);
echo $strSQL;
mysql_query($strSQL) or die(mysql_error());
echo 'บันทึกข้อมูลเรียบแล้วร้อย';
}
?>
Tag : PHP, MySQL
|
|
 |
 |
 |
 |
Date :
2016-10-25 15:49:41 |
By :
fzjameza |
View :
979 |
Reply :
10 |
|
 |
 |
 |
 |
|
|
|
 |