我正在開發一個高級項目,我一直在開發一個使用PHP從數據庫讀取/寫入數據的站點。我可以成功讀取數據到網站,但是在寫入數據時,我無法用網站上的表單數據填充我的Oracle數據庫。假設連接是正確的,因爲這與我用來讀取數據的連接是一樣的,並且它工作正常。PHP:爲什麼我的代碼不能插入數據庫
if($_POST['formSubmit'] == "Submit")
{
// Add validation code here
// Variable definition -- student info
$varOrg = $_POST['orgdept'];
$varFirst = $_POST['first'];
$varLast = $_POST['last'];
$varUID = $_POST['uid'];
$varStudentEmail = $_POST['semail'];
$varPhone = $_POST['sphone'];
$varOrgEmail = $_POST['orgemail'];
$varAdvisorName = $_POST['advisorname'];
// Variable definition -- event info
$varEventName = $_POST['eventname'];
$varEventDate = $_POST['eventDate'];
$varStartTime = $_POST['startTime'];
$varEndTime = $_POST['endTime'];
$varAttendance = $_POST['attendance'];
$varOpenTo = $_POST['opento'];
// ADD code for recurring dates
// Variable definition -- event logistics
$varEventType = $_POST['eventtype'];
$varOtherType = $_POST['othertypein'];
$varLocation = $_POST['locationselect'];
$varOtherIN = $_POST['inother1'];
$varPrefRoom1 = $_POST['proom1'];
$varPrefRoom2 = $_POST['proom2'];
$varOtherOUT = $_POST['outother1'];
$varDMNecess = $_POST['dmnecess'];
$varDMPowerON = $_POST['poweron'];
$varDMPowerOFF = $_POST['poweroff'];
$varDescription = $_POST['description'];
// Variable definition - add'l necessities
$varAmpSoundDesc = $_POST['ampsound'];
$varSecurityDesc = $_POST['security'];
$varFoodDesc = $_POST['food'];
$varChildrenDesc = $_POST['children'];
$varElectricityDesc = $_POST['electricity'];
$varSponsorshipDesc = $_POST['sponsorship'];
// Variable definition - signature/date
$varSignature = $_POST['signature'];
$varSignDate = $_POST['signdate'];
$db = oci_connect('ASSUME CORRECT');
if (!$db) {
$e = oci_error();
trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR);
die("Error connecting to the database.");
}
else
{
$sql = "INSERT INTO EVENT(EVENT_ID, STATUS, GROUP_NAME, STUDENTID, CONTACT_FIRST, CONTACT_LAST, EMAIL, PHONE, EVENT_NAME, EVENT_START, EVENT_END, ATTENDANCE, E_LOCATION, EVENT_TYPE, E_DESCRIPTION, EVENT_DATE) ' .
'VALUES (SEQ_ID.NEXTVAL, 'PENDING', :groupname, :studentid, :first, :last, :email, :phone, :eventname, to_date(:eventstart, 'HH24:MI'), to_date(:eventend, 'HH24:MI'), :attendance, :location, :eventtype, :description, to_date(:eventdate, 'YYYY-MM-DD')); ";
$compiled = oci_parse($db, $sql);
oci_bind_by_name($complied, ':groupname', $varOrg);
oci_bind_by_name($compiled, ':studentid', $varUID);
oci_bind_by_name($compiled, ':first', $varFirst);
oci_bind_by_name($compiled, ':last', $varLast);
oci_bind_by_name($compiled, ':email', $varStudentEmail);
oci_bind_by_name($compiled, ':phone', $varPhone);
oci_bind_by_name($compiled, ':eventname', $varEventName);
oci_bind_by_name($compiled, ':eventstart', $varStartTime);
oci_bind_by_name($compiled, ':eventend', $varEndTime);
oci_bind_by_name($compiled, ':attendance', $varAttendance);
oci_bind_by_name($compiled, ':location', $varLocation);
oci_bind_by_name($compiled, ':eventtype', $varEventType);
oci_bind_by_name($compiled, ':description', $varDescription);
oci_bind_by_name($compiled, ':eventdate', $varEventDate);
oci_execute($compiled);
}
}
?>
我已經給所有控件添加了名稱屬性,但它並沒有給我任何東西發佈到數據庫。誰能提供指導?
當你發送表單數據,這是怎麼回事?你有錯誤嗎?它是否總是失敗或者只有表單數據中的某些類型的值? – Kmeixner
你有什麼錯誤? –
你不是通過PHP檢查錯誤。在打開PHP標記 (例如'<?php error_reporting(E_ALL);)後立即在文件頂部添加錯誤報告。 ini_set('display_errors',1);'然後你的代碼的其餘部分,看看它是否產生任何東西。正如下面的答案所示,最有可能發生變量錯配。您還應該檢查查詢中的錯誤。 –