Teach you how to use Oracle database in PHP (3)
Use ORA to input data into the data table 'email_info'
When the user browses this script, a form consisting of name and email input fields is displayed; when the user adds the data and clicks submit, the script program will save the name and email to the 'email_info' data table.
Related php code:
if ($submit == "click"){
// The submit button was clicked!
// Get the input for fullname and email then store it in the database.
PutEnv("Oracle_SID=ORASID");
$connection = Ora_Logon ("username","passWord");
if ($connection == false){
echo Ora_ErrorCode($connection).": ".Ora_Error($connection)."
";
exit;
}
$cursor = Ora_Open ($connection);
if ($cursor == false){
echo Ora_ErrorCode($connection).": ".Ora_Error($connection)."
";
exit;
}
$query = "insert into email_info values ('$fullname', '$email')";
$result = Ora_Parse ($cursor, $query);
if ($result == false){
echo Ora_ErrorCode($cursor).": ".Ora_Error($cursor)."
";
exit;
}
$result = Ora_Exec ($cursor);
if ($result == false){
echo Ora_ErrorCode($cursor).": ".Ora_Error($cursor)."
";
exit;
}
Ora_Commit ($connection);
Ora_Close ($cursor);
Ora_Logoff ($connection);
}
else{
echo '
<FORM action=insert.php method=post>
Please enter your name
<INPUT name=fullname></INPUT>
Please enter your email address
<INPUT name=email></INPUT>
<INPUT name=submit type=submit value=click></INPUT> <
</FORM>
';
}
?>
By the way, this script must be saved as insert.php, because insert.php is specified as the form handler in the page called.
The above has introduced how to use Oracle database in PHP (Part 3), including the content. I hope it will be helpful to friends who are interested in PHP tutorials.