Home: Perl Programming Help: Beginner:
Please help me in insert statement



datlaravi
Deleted

Jun 6, 2000, 12:42 PM


Views: 1261
Please help me in insert statement

Hi,
I want to get the form value and insert into
the database. The html for the formfield is
for example
//file work.cgi
use CGI;
$query = new CGI;
$building =$query->param{'buildName'};
&printform;
sub printform {
<form name ="build" method ="post" action="work.cgi"> (same file has sub routines)

<TD> <input type="text" size="10" name="buildName"></TD>
<TD> <input type ="submit" name = "buildAdd" value ="BAdd">
}
The code i have is
if (($in{buildAdd} eq "BAdd")) {

&addBuilding;
}

sub addBuilding {
$insert = "insert ConferenceRooms values ('$building', "a123", 234, 0,0,0,0,0,"234-567-7890","345-346-8798")";
$sybHandle=$syb->prepare($insert);
$sybHandle->execute() &#0124; &#0124; &writeError('User cannot be added');
$sybHandle->finish();
#$message = "<b>User Added</b><p>";
}
I am getting an error at the insert statement.Please help me. Can you send me an email so i can send as an attachment.
Can i have 2 submit buttons in the same form with the post method going to the same file (eg: work.cgi)


dws
Deleted

Jun 6, 2000, 8:56 PM


Views: 1261
Re: Please help me in insert statement

Try "insert into ConferenceRooms ..."

Also check your quotes. You either need to escape some of the double quotes or use single quotes.


[This message has been edited by dws (edited 06-06-2000).]


CuzDesign
Deleted

Jun 8, 2000, 1:54 AM


Views: 1261
Re: Please help me in insert statement

Hello,
In answer to the following question:
<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">quote:</font><HR>
Can i have 2 submit buttons in the same form with the post method going to the same file (eg: work.cgi)
<HR></BLOCKQUOTE>

Yes you can use more then one submit to go to the same program, however you need to use them both seperate in there own form tags.

Also in your program if each of the "Submit" buttons is to run different parts of the program you need to check and see which part of the program to run, such as this.

If "Submit" button 1 is clicked, then go to and do sub submit1{}.

If "Submit" button 2 is clicked go to and do sub submit2{}.

Now you should use an action input tag to tell your program what you are trying to do and then test it when the program is called.

Example:
<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>


$action = param('action');
if ($action eq 'sub1') { &submit1 }
elsif ($action eq 'sub2') { &submit2 }
</pre><HR></BLOCKQUOTE>

Basically that says if the input tag actions value is "sub1" go to and do sub submit1 and the same for sub submit2.

This way you could put 2 or more forms on one page that do 2 different things using the same program.

Hope this helps.

Regards,
Ray


datlaravi
Deleted

Jun 8, 2000, 6:29 AM


Views: 1261
Re: Please help me in insert statement

Thanks for your help. It works.


monocle
User

Jun 8, 2000, 7:14 AM


Views: 1261
Re: Please help me in insert statement

 <BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">quote:</font><HR>
Yes you can use more then one submit to go to the same program, however you need to use them both seperate in there own form tags.
<HR></BLOCKQUOTE>
Actually you can have multiple submit buttons in the same form tag. You are correct though in speaking of the need to evaluate the buttons to see which action is meant to be done but you will need to test the name or the value(caption) of the button.

Monocle
Hear great techno music by Monocle at http://www.mp3.com/monocle


[This message has been edited by monocle (edited 06-08-2000).]