?
Solved

Building forms

Posted on 2005-04-25
12
Medium Priority
?
176 Views
Last Modified: 2012-06-27
I am trying to create a form page whereby users can ask questions click submit it sends an email to a designated person, saves to a data base and also posts to anaother form. Almost like what you have here
0
Comment
Question by:iolike
6 Comments
 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 13859564
Most of what you need is server side, so we will need to know what you have available as database and server side scripting language.

Cd&
0
 

Author Comment

by:iolike
ID: 13859616
I have Oracle data base and I would like to use PLSQL or May be SQL Statement.  I have four column in the table. The columns are Question, Answer, Response, and Date.


Thank you
0
 
LVL 3

Expert Comment

by:ChastityMan
ID: 13860816
I don't know what server side language you are doing, so I'll give you the answer using PHP.

First you have to be able to connect to the oracle database.  Do this via the ORA module.  Enable this module if it came precompiled with your version of PHP by editing the php.ini file and uncommenting the following line:  "extension = php_oracle.dll"

If you version of PHP doesn't have this module, you will need to recompile PHP using the following option:  "--with-oracle=/path/to/oracle/home/dir"


Once that is done, your form should look something like this:
<form id="formname" action="proc_form.php" method="post">
    <input id="question" type="text"></input>
    <input id="answer" type="text"></input>
    <input id="response" type="text"></input>
    <input id="date" type="text"></input>
    <input type="submit" value="<whatever text you want to appear on the button>"></input>
</form>

In the proc_form.html file (or whichever file is processing your form as specified in the ACTION property of the form) you need to have code to connect to the oracle database.  This code should look something like this:
<?php
    if ($c=ora_logon("user@server","password"))
    {
        echo "Successfully connected to Oracle.\n";
        ora_commitoff($c);
        ora_logoff($c);
    }
    else
    {
        echo "Oracle Connect Error " . ora_error();
    }
?>

Then you need to add the information to the database using code such as this:
$query = "INSERT INTO <datatable> (question, answer, response, date) VALUES ('" . $_POST['question'] . "', '" . $_POST['answer'] . "', '" . $_POST['response'] . "', '" . $_POST['date']. "')";

$result = mysql_query($query);

if(! $result)
{
    // Print an error message if the insert failed.
}

Then send an email like this:
mail($to, $subject, $contents, $from_header);

Of course, you need to either create text in the $to, $subject, $contents, and $form_header variables, or you can just pass the text directly as command line parameters (although that can get ugly).

Let me know if you have any other questions.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:iolike
ID: 13880519
Thank you so much for this but my serevr side is actually ASP and I have move the database to Microsoft Access, So How do I go around achieveing this.
0
 
LVL 13

Accepted Solution

by:
jrram earned 1000 total points
ID: 13892348
Once that is done, your form should look something like this:
<form id="formname" action="proc_form.asp" method="post">
    <input id="question" type="text"></input>
    <input id="answer" type="text"></input>
    <input id="response" type="text"></input>
    <input id="date" type="text"></input>
    <input type="submit" value="<whatever text you want to appear on the button>"></input>
</form>

In the proc_form.asp file (or whichever file is processing your form as specified in the ACTION property of the form) you need to have code to connect to the access database.  This code should look something like this:
<%

question = Request.Form("question")
answer = Request.Form("answer")
rsp = Request.Form("response")
dateVal = Request.Form("date")

'***** begin ESTABLISH DATABASE CONNECTION ******

 Dim objConn
 Dim strConnString
 Dim objRS
 
 Set objConn = Server.CreateObject("ADODB.Connection")
 Set objRS = Server.CreateObject("ADODB.Recordset")

 dataConn = Server.MapPath("<databaseName>.mdb")
 objConn.Open "Driver={Microsoft Access Driver (*.mdb)};DBQ=" & dataConn & ";"
 
  '***** end ESTABLISH DATABASE CONNECTION *****

' ** Insert data into db
insertSQL = "INSERT INTO <tableName> (question, answer, response, date) VALUES ('" & _
question & "', '" & answer  & "', '" & rsp & "', '" & dateVal & "');"

objConn.Execute insertSQL

'** Mail data

 Set emailX = CreateObject("CDONTS.NewMail")
 
 emailX.From = "<address>@<domain>"
 emailX.To = "<address>@<domain>"

 emailX.Subject = "<-X- subject>"

 emailX.MailFormat = 0
 emailX.BodyFormat = 0

 msgDetails = msgDetails & "Question: " & question & vbCr
 msgDetails = msgDetails & "Answer: " & answer & vbCr
 msgDetails = msgDetails & "Response: " & rsp & vbCr
 msgDetails = msgDetails & "Date: " & dateVal & vbCr

 emailX.Body = msgDetails

 On Error Resume Next
 
 emailX.Send
 
 If Err.Number = 0 Then
   resultMsg = "Your message has been sent."
 Else
   resultMsg =  "Error: " & Err.Description
 End If
 
 Set Message = Nothing

 'Response.Redirect("whateverPage.asp")
%>

0
 

Author Comment

by:iolike
ID: 14069461
Sorry I think I accepted the wrong one. How do I correct this.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When the s#!t hits the fan, you don’t have time to look up who’s on call, draft emails, call collaborators, or send text messages. An instant chat window is definitely the way to go, especially one like HipChat. HipChat is a true business app. An…
Ready to get certified? Check out some courses that help you prepare for third-party exams.
This tutorial demonstrates how to identify and create boundary or building outlines in Google Maps. In this example, I outline the boundaries of an enclosed skatepark within a community park.  Login to your Google Account, then  Google for "Google M…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses
Course of the Month16 days, 3 hours left to enroll

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question