นี่เป็นโค้ด ไฟล์ insert.php คับ
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "office";
try {
$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
// set the PDO error mode to exception
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = "INSERT INTO company (office, Country, territory, Name, Address, Streets, District, SubDistrict, PostelCode, Tel, Fax, Website, Email, Latitude, Longtitude, BusinessType, Productone, Producttwo, Producttree, Productfour, Contact_Person_title, FirstName,
MiddleName, Surname, Telephone_number, Email_Person, Note_Needs_title, date_created, date_modifile, register, typed_by, file)
VALUES ('$_POST[office]', '$_POST[Country]', '$_POST[territory]', '$_POST[name]', '$_POST[Address]', '$_POST[Streets]', '$_POST[District]', '$_POST[SubDistrict]', '$_POST[PostelCode]', '$_POST[Tel]', '$_POST[Fax]' , '$_POST[Website]',
'$_POST[Email]', '$_POST[Latitude]', '$_POST[Longtitude]', '$_POST[BusinessType]', '$_POST[Productone]', '$_POST[Producttwo]', '$_POST[Producttree]', '$_POST[Productfour]', '$_POST[Contact_Person_title]', '$_POST[FirstName]', '$_POST[MiddleName]', '$_POST[Surname]',
'$_POST[Telephone_number]', '$_POST[Email_Person]', '$_POST[Note_Needs_title]', '$_POST[date_created]', '$_POST[date_modifile]', '$_POST[register]', '$_POST[typed_by]', '$_POST[file]')";
// use exec() because no results are returned
$conn->exec($sql);
echo "New record created successfully";
}
catch(PDOException $e)
{
echo $sql . "<br>" . $e->getMessage();
}
$conn = null;
?>
/// ตอนแรกรันโค้ดได้ปกติคับ แต่สักพักมันขึ้น error ว่า Notice: Undefined index: file in C:\xampp\htdocs\book\img\insert.php on line 15
ซึ่งหมายถึง ซึ่งมันบอกว่า file ไม่ได้กำหนดค่า ซึ่งผมได้กำหนดค่าเรียบร้อยแล้วคับ แบบนี้ผมควรแก้ตรงไหนอ่าคับ ??
ขอช่วยแก้ไขโค้ด PHP หน่อยครับ
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "office";
try {
$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
// set the PDO error mode to exception
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = "INSERT INTO company (office, Country, territory, Name, Address, Streets, District, SubDistrict, PostelCode, Tel, Fax, Website, Email, Latitude, Longtitude, BusinessType, Productone, Producttwo, Producttree, Productfour, Contact_Person_title, FirstName,
MiddleName, Surname, Telephone_number, Email_Person, Note_Needs_title, date_created, date_modifile, register, typed_by, file)
VALUES ('$_POST[office]', '$_POST[Country]', '$_POST[territory]', '$_POST[name]', '$_POST[Address]', '$_POST[Streets]', '$_POST[District]', '$_POST[SubDistrict]', '$_POST[PostelCode]', '$_POST[Tel]', '$_POST[Fax]' , '$_POST[Website]',
'$_POST[Email]', '$_POST[Latitude]', '$_POST[Longtitude]', '$_POST[BusinessType]', '$_POST[Productone]', '$_POST[Producttwo]', '$_POST[Producttree]', '$_POST[Productfour]', '$_POST[Contact_Person_title]', '$_POST[FirstName]', '$_POST[MiddleName]', '$_POST[Surname]',
'$_POST[Telephone_number]', '$_POST[Email_Person]', '$_POST[Note_Needs_title]', '$_POST[date_created]', '$_POST[date_modifile]', '$_POST[register]', '$_POST[typed_by]', '$_POST[file]')";
// use exec() because no results are returned
$conn->exec($sql);
echo "New record created successfully";
}
catch(PDOException $e)
{
echo $sql . "<br>" . $e->getMessage();
}
$conn = null;
?>
/// ตอนแรกรันโค้ดได้ปกติคับ แต่สักพักมันขึ้น error ว่า Notice: Undefined index: file in C:\xampp\htdocs\book\img\insert.php on line 15
ซึ่งหมายถึง ซึ่งมันบอกว่า file ไม่ได้กำหนดค่า ซึ่งผมได้กำหนดค่าเรียบร้อยแล้วคับ แบบนี้ผมควรแก้ตรงไหนอ่าคับ ??