我正在开发一个高级项目,我一直在开发一个使用PHP从数据库读取/写入数据的站点。我可以成功地将数据读取到站点,但是在编写数据时,我无法使用站点上的表单数据填充Oracle数据库。假设连接是正确的,因为我使用相同的连接来读取数据并且它可以正常工作。
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);
}
}
?>
我已经为所有控件添加了名称属性,但它没有让我发布到数据库的任何内容。有人可以提供指导吗?
答案 0 :(得分:0)
你的一个变量中有一个拼写错误。
oci_bind_by_name($complied, ':groupname', $varOrg);
^^^^^^^^^
它应显示为$compiled
oci_bind_by_name($compiled, ':groupname', $varOrg);
答案 1 :(得分:0)
正确检查Sql查询
$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')); ";
答案 2 :(得分:0)
查看代码的这一行:
$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')); ";
在第一行打开带有双引号的$sql
字符串,然后用单引号将其关闭。在连接线上,用单引号打开它,并用双引号将其关闭。
替换为:
$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')); ";
也查看这一行:
oci_bind_by_name($complied, ':groupname', $varOrg);
您将compiled
拼错为complied
。
替换为:
oci_bind_by_name($compiled, ':groupname', $varOrg);