将记录从html表单添加到oracle数据库

时间:2014-03-24 16:14:07

标签: php sql html5 oracle

我有一个HTML表单,我希望在有人点击提交时将记录添加到Oracle数据库。该表有点挂钩,问题是当有人提交他们的信息时,他们会在数据库表中显示为NULL值。

HTML:

<form name="myForm" action="/Add_File.php" onsubmit="return validateForm()" method="post"><!--Form-->
<fieldset>
    <label class ="label1" for "name">First Name: </label>
    <input type="text" name="fname"><br />
    <label class ="label1" for "name">Surname: </label><input type="text" name="sname"><br/>
    <label for="email">E-mail Address: </label><input type="text" name="email"><br />
    <label  for "address">Address: </label> <input type="text" name="address"><br />
    <label class="label" for "Password">Select a Password: </label> <input type="password" name="pass"><br />
    <label class="label" for "Password">Retype-Password:</label> <input type="password" name="pass2"><br />
</fieldset>
<fieldset><input class="button" type="submit" onclick="message()" value="Submit"/>
    <input class="button" type="reset" value="reset form" onclick="myFunction()"/>
</fieldset>
</form>

PHP代码:

$dbuser = "scott";
$dbpassword = "tiger";
$db = "orabis";
$conn = oci_connect($dbuser,$dbpassword,$db);

if (!$conn){
    echo "Connection error";
    exit;
}

$fname=$_POST['First_Name'];
$sname=$_POST['Surname'];
$email=$_POST['Email_Address'];
$address=$_POST['Address'];
$selpass=$_POST['Select_A_Password'];
$confirm=$_POST['Retype_Password'];

$sql = "INSERT INTO Become_A_Member_110385461(First_Name,Surname,Email_Address,Address,Select_A_Password,Retype_Password) 
VALUES ('".$fname."','".$sname."', '".$email."', '".$address."','".$selpass."', '".$confirm."')";

$stmt = oci_parse($conn, $sql);
if (!$stmt) {
    echo "Error in preparing the statement";
    exit;
}

oci_execute($stmt, OCI_DEFAULT);
print "Record Inserted";
oci_commit($conn);
oci_close($conn);

1 个答案:

答案 0 :(得分:1)

像这样改变

$fname=$_POST['fname'];
$sname=$_POST['sname'];
$email=$_POST['email'];
$address=$_POST['address'];
$selpass=$_POST['pass'];
$confirm=$_POST['pass2'];