Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: How to bind html page with PERL script to accept user input to Mysql database (eg. Phonebook)

by ww (Archbishop)
on Jul 04, 2013 at 00:54 UTC ( [id://1042307]=note: print w/replies, xml ) Need Help??


in reply to Re^2: How to bind html page with PERL script to accept user input to Mysql database (eg. Phonebook)
in thread How to bind html page with PERL script to accept user input to Mysql database (eg. Phonebook)

"Where...?" That's one of the (implicit) questions I posed for you. Your server's administrator should know. If you're the admin, you need to find out... and to learn the answers to the other questions/ambiguities above. I don't have any way of offered more than alternatives... and you need to learn those alts yourself.

Update: Missed your ref to putting the script in a sub-folder of cgi-bin. That's probably OK, but you'll have to account for that sub-dir in your form action element. Otherwise, Apache will go looking for your script in (some?) cgi-bin and not find it. /Update

But I'm pretty confident that there's NO NEED NOR REASON to put the .html in cgi-bin. In fact, it's sometimes regarded as very bad practice.

UPDATE: NB OP's text between my markup, ***1 and /***1.

OP has updated the node text & the html (form action path) in the top node of this thread. The original content went like this:

Hi, I am new to PERL. I am using Padre and wrote a PERL script to connect to database. I also created a html form for user input. How to bind html page with PERL script to accept user input to Mysql database (eg. Phonebook). ***1 The idea is to open browser on running the script for user input to add/delete/update entries from the database.
When I run this script, it adds a blank row to database, but doesn't open the html page where I am supposed to add values. /***1
I have Apache running but my files are in a perl project folder. Do I need to shift my project to cgi-bin? Here is my html file contactsform.html:

<html> <head><title>ADDRESS BOOK</title></head> <body bgcolor="#FFFFFF" link="#0000FF" alink="#FF0000" vlink="#C000FF" +> <h1>ADDRESS BOOK CONTACTS</h1> <table> <form method="post" action="sqlconfig.pl"> <tr> <td align="right">Last Name:</td> <td align="left"><input type="text" name="lname" size="15" maxlength +="50"></td> <td align="right">First Name:</td> <td align="left"><input type="text" name="fname" size="15" maxlength +="50"></td> </tr> <tr> <td align="right">Phone:</td> <td align="left"><input type="text" name="phone" size="15" maxlength +="50"></td> <td align="right">Email:</td> <td align="left"><input type="text" name="email" size="15" maxlength +="50"></td> </tr> <tr> <td align="right">Address:</td> <td align="left"><input type="text" name="address" size="15" maxleng +th="50"></td> <td align="right">Zip Code:</td> <td align="left"><input type="text" name="zip" size="15" maxlength=" +50"></td> </tr> </table> <input type="submit" value="Submit" onclick="addcontact"> </form> </body> </html>

And this is the perl script sqlconfig.pl:

#!c:/Dwimperl/perl/bin/perl.exe # PERL MODULES WE WILL BE USING use CGI; use DBI; use DBD::mysql; use HTML::TEMPLATE; # Config DB variables our $platform = "mysql"; our $database = "test"; our $host = "localhost"; our $port = "3306"; our $tablename = "addressbook"; our $user = "root"; our $pw = "password"; our $q = new CGI; # DATA SOURCE NAME $dsn = "dbi:mysql:$database:localhost:3306"; # PERL DBI CONNECT $connect = DBI->connect($dsn, $user, $pw); #Get the parameter from your html form. $lname=$q->param('lname'); $fname=$q->param('fname'); $phone=$q->param('phone'); $email=$q->param('email'); $address=$q->param('address'); $zip=$q->param('zip'); print $q->header; $sql="INSERT INTO test.addressbook(last_name,first_name) values('$lnam +e','$fname')"; $sth = $connect->prepare($sql) or die "Can't prepare $sql: $connect->errstrn"; #pass sql query to database handle.. $rv = $sth->execute or die "can't execute the query: $sth->errstrn"; #execute your query if ($rv==1){ print "Record has been successfully updated !!!n"; }else{ print "Error!!while inserting recordn"; exit; }

The announced, but non-specific edit may have occasioned considerable confusion below.

I was certainly confused (and may still be) BUT -- upon trying to explain why the original raised the bad path suspicion (eg, that Apache doesn't expect to find executables in a "perl project folder" -- I discovered the language now marked by ***1.

Does anyone else read that, in paraphrase, as I am calling the script by some unspecified means -- perhaps even from the C:> prompt -- and expect it to somehow cause my browser to start and read the html form -- or have I just been looking at this too long?

meh!


If you didn't program your executable by toggling in binary, it wasn't really programming!

  • Comment on Re: How to bind html page with PERL script to accept user input to Mysql database (eg. Phonebook)
  • Select or Download Code

Replies are listed 'Best First'.
Re^4: How to bind html page with PERL script to accept user input to Mysql database (eg. Phonebook)
by Shuraski (Scribe) on Jul 04, 2013 at 15:30 UTC

    It looks like the OP is running the SQL db off his/her local machine, using that as the server. If that's not the case and the server is a different machine, I agree, the path to that server looks wrong. Can the OP clarify where the db is located? Localhost or another machine?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1042307]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (2)
As of 2024-04-20 06:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found