|
 |
|
อัพโหลดภาพลงฐานข้อมูลแบบเก็บชื่อภาพ แต่ในฐานข้อมูลไม่มีชื่อไฟล์ |
|
 |
|
|
 |
 |
|
แค่ echo ไม่ query มันจะเข้าฐานข้อมูลได้ไงครับ
|
 |
 |
 |
 |
Date :
2011-02-06 21:30:15 |
By :
PlaKriM |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
คือผมก็ลองทำใหม่อีกทีน่ะครับ คราวนี้อัพภาพได้แต่ดันไม่อยู่ในแถวเดียวกัยในฐานข้อมูลน่ะครับ คือว่ามันแยกกันเก็บกับข้อมูลอื่นๆเลยครับ
ลองดูโค๊ดให้หน่อยนะครับ
Code (PHP)
<?php
// ส่วนกำหนดการเชื่อมต่อฐานข้อมูล
$hostname_connection = "localhost";
$database_connection = "ย";
$username_connection = "า";
$password_connection = "ก";
$connection = mysql_pconnect($hostname_connection, $username_connection, $password_connection)
or trigger_error(mysql_error(),E_USER_ERROR);
mysql_query( "SET NAMES UTF8" ) ;
// Include คลาส class.upload.php เข้ามา เพื่อจัดการรูปภาพ
require_once('class/class.upload.php') ;
// ถ้าหากหน้านี้ถูกเรียก เพราะการ submit form
// ประโยคนี้จะเป็นจริงกรณีเดียวก็ด้วยการ submit form
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
// เริ่มต้นใช้งาน class.upload.php ด้วยการสร้าง instant จากคลาส
$upload_image = new upload($_FILES['logo']) ; // $_FILES['image_name'] ชื่อของช่องที่ให้เลือกไฟล์เพื่ออัปโหลด
// ถ้าหากมีภาพถูกอัปโหลดมาจริง
if ( $upload_image->uploaded ) {
// ย่อขนาดภาพให้เล็กลงหน่อย โดยยึดขนาดภาพตามความกว้าง ความสูงให้คำณวนอัตโนมัติ
// ถ้าหากไม่ต้องการย่อขนาดภาพ ก็ลบ 3 บรรทัดด้านล่างทิ้งไปได้เลย
$upload_image->image_resize = true ; // อนุญาติให้ย่อภาพได้
$upload_image->image_x = 1000 ; // กำหนดความกว้างภาพเท่ากับ 400 pixel
$upload_image->image_ratio_y = true; // ให้คำณวนความสูงอัตโนมัติ
$upload_image->process( "simmage" ); // เก็บภาพไว้ในโฟลเดอร์ที่ต้องการ *** โฟลเดอร์ต้องมี permission 0777
// ถ้าหากว่าการจัดเก็บรูปภาพไม่มีปัญหา เก็บชื่อภาพไว้ในตัวแปร เพื่อเอาไปเก็บในฐานข้อมูลต่อไป
if ( $upload_image->processed ) {
$logo = $upload_image->file_dst_name ; // ชื่อไฟล์หลังกระบวนการเก็บ จะอยู่ที่ file_dst_name
$upload_image->clean(); // คืนค่าหน่วยความจำ
// เก็บชื่อภาพลงฐานข้อมูล
$insertSQL = sprintf("INSERT INTO supplier (logo) VALUES ( '%s' )", $logo );
echo $insertSQL ;
mysql_select_db($database_connection, $connection);
$Result1 = mysql_query($insertSQL, $connection) or die(mysql_error());
}// END if ( $upload_image->processed )
}//END if ( $upload_image->uploaded )
}
session_start();
if($_POST) {
$Username = $_POST['user'];
$Password = $_POST['pw'];
$repwd = $_POST['repwd'];
$sname = $_POST['company'];
$license = $_POST['license'];
$country = $_POST['country'];
$keywords = $_POST['keywords'];
$type = $_POST['type'];
$year = $_POST['year'];
$profile = $_POST['profile'];
$address = $_POST['address'];
$logo = $_POST['logo'];
$photo = $_POST['photo'];
$address = $_POST['address'];
$email = $_POST['email'];
$gbuser = $_POST['gbuser'];
$web = $_POST['web'];
if(empty($Username)) {
$errmsg = "please input your user name";
}
else if($Password != $repwd) {
$errmsg = "the password is not match!";
}
else if(!eregi("[a-z0-9]{1,10}", $Password)) {
$errmsg = "the password must be contain a-z, 0-9 , 1-10 only";
}
if(empty($sname)) {
$errmsg = "please input your company name";
}
else if(empty($license)) {
$errmsg = "please input your company license number";
}
else if(empty($country)) {
$errmsg = "please select your country";
}
else if(empty($keywords)) {
$errmsg = "input your specific location ie, town, beach , city";
}
else if(empty($type)) {
$errmsg = "please select type of your company";
}
else if(empty($year)) {
$errmsg = "please input the open year of your company";
}
else if(empty($profile)) {
$errmsg = "please input your company profile and information";
}
else if(empty($address)) {
$errmsg = "please input your company address";
}
else if(!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$errmsg = "incorrect email";
}
else if(empty($gbuser)) {
$errmsg = "please input your gubig account name for business comunication";
}
else if(empty($web)) {
$errmsg = "please input your website URL";
}
if($errmsg != "") {
echo "<font size=5 color=red>$errmsg<p />
<a href=\"javascript: history.back()\">back to main page</a></font>";
}
else {
include("gubig.inc.php");
my_connect();
$sql = "INSERT INTO supplier VALUES ('','$Username','$Password','$repwd','$sname', '$license', '$country','$keywords', '$type', '$year', '$profile','$address', '$logo','$email', '$gbuser', '$web','$Status','$preview','$link');";
@mysql_query($sql) or die(mysql_error());
header("Location:home.php");
echo "welcome to gubig family";
}
exit;
}
?>
ผมคิดว่ามันเป็นเพราะมันเชื่อมต่อฐานข้อมูลสองครั้ง แต่ผมก็ไม่รู้ว่าต้องแก้ตรงใหนน่ะครับ ช่วยดูให้หน่อยนะครับ
|
 |
 |
 |
 |
Date :
2011-02-07 11:36:44 |
By :
thanadol |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 00
|