Advertisement

11.26.2007 at 05:15AM PST, ID: 22982250
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

7.0

Perl and databases

Asked by catonthecouchproductions in Perl Programming Language

I have a script that an expert here helped me write and I am trying to get it now to create the TABLE in the database, any suggestions?

I am stuck on that part, the writing.

I have the script here - http://elan.champlain.edu/~rcoughlin32001/cgi-bin/table.cgi

I placed in all of my connection information, etc. I want to write this to the DB:

            >> print(" CREATE TABLE $table( $tableFields );");

Thanks!
RyanStart Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
#!/usr/bin/perl
use CGI qw(:standard);
use DBI;
print "Content-type:text/html \n\n";
 
 
# Ryan Coughlin
# Server Side Scripting
# Breaks code down in to subs
# sub header - print out top HTML code (body tags)
# sub footer - ends HTML page
# sub first  - enter table name and number of fields
# sub second - enter details on each field
# sub three  - prints out SQL create table code
 
# connection details for connection to database
 
$database = "assignments";
$username = "web320";
$password = "web320pass";
 
# make connection string
 
$dsn      = "DBI:mysql:$database:localhost";
 
# make actual connection
 
$dbh=DBI->connect($dsn,$username,$password); # if a password is not required renove $password
 
 
 
 
my $step = param('step') || "START"; # what step are you on
 
if( $step eq "Create Table")
{
      my $table   = param('tableName')   || "TEST";    # table name
      my $fields  = param('fieldCount')  || 0;         # number of fields
      third($table,$fields);
}
elsif( $step eq "Submit")
{
      my $table   = param('tableName');                # table name
      my $fields  = param('fieldCount') || 0;          # number of fields
 
      second("table.cgi","post",$table, $fields);
}
else
{
      first("table.cgi","post");
}
footer();
 
##logic ends here. Only subroutines follow
 
sub header{
my ($pageTitle,$headCode)=@_;
 
print <<HEADER;
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>$pageTitle</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
$headCode
</head>
 
<body>
HEADER
 
}
 
sub footer{
print <<FOOTER;
</body>
</html>
FOOTER
 
}
 
 
# first step type in table name and number of fields
sub first{
my ($action,$method)=@_;
 
print <<FIRST;
<h2>Building and Using a Database</h2>
<h2>Step 1: Name of Table and Number of Fields</h2>
<form id="form1" method="$method" action="$action">
  <p><b>Table Name:</b>
    <input name="tableName" type="text" size="10" maxlength="10" />
 
  </p>
  <p><b>Number of Fields</b>:
    <input name="fieldCount" type="text" size="10" maxlength="10" />
  </p>
  <p>
    <input type="submit" name="step" value="Submit" />
  </p>
 
</form>
 
<p>&nbsp;</p>
FIRST
 
}
 
# type in field characteristics
sub second{
# print out outer HTML form/table, etc.
my ($action,$method,$table,$fields) = @_;
 
print <<HTML;
 
<form id="form1" method="$method" action="$action">
      <input type="hidden" name="tableName" value="$table" />
      <input type="hidden" name="fieldCount" value="$fields" />
      <table width="60%" border="2" cellspacing="0" cellpadding="0">
          <caption>$table</caption>
            <tr>
                  <td><b>FIELD NAME</b></td>
                  <td><b>FIELD TYPE</b></td>
                  <td><b>FIELD LENGTH</b></td>
            </tr>
HTML
 
# print out the number of fields specified in step 1 us basic for loop statement
for ($counter=1; $counter <= $fields; ++$counter){
      print <<HTML1;
            <tr>
                  <td><input name="fieldname$counter" type="text" size="30" maxlength="30" /></td>
                  <td>
                        <select name="fieldtype$counter">
                              <option value="char">char</option>
                              <option value="date">date</option>
                              <option value="float">float</option>
                              <option value="int">int</option>
                              <option value="text">text</option>
                              <option value="varchar">varchar</option>
                        </select>
                  </td>
                  <td><input name="fieldlength$counter" type="text"  size="5" maxlength="5" /></td>
            </tr>
       
HTML1
 
}
print <<HTML3;
      </table>
 
      <p><input type="submit" name="step" value="Create Table" /></p>
</form>
 
HTML3
 
}
 
# prints out SQL code - will print all fields and characteristics
sub third{
my ($table,$fieldCount) = @_;
 
my $tableFields = "";
for($i=1; $i<$fieldCount; ++$i)
{
$tableFields .= param("fieldname$i") . " " . param("fieldtype$i") . "(" . param("fieldlength$i") . "), ";
}
$tableFields .= param("fieldname$i") . " " . param("fieldtype$i") . " (" . param("fieldlength$i") . ")";
 
# print out
print(" CREATE TABLE $table( $tableFields );");
}
[+][-]11.26.2007 at 05:21AM PST, ID: 20349610

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11.26.2007 at 05:23AM PST, ID: 20349623

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11.26.2007 at 05:36AM PST, ID: 20349684

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11.26.2007 at 05:43AM PST, ID: 20349710

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11.26.2007 at 05:46AM PST, ID: 20349719

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11.26.2007 at 05:55AM PST, ID: 20349787

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11.26.2007 at 06:00AM PST, ID: 20349821

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11.26.2007 at 06:05AM PST, ID: 20349845

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: Perl Programming Language
Sign Up Now!
Solution Provided By: BioI
Participating Experts: 1
Solution Grade: A
 
 
[+][-]11.26.2007 at 06:06AM PST, ID: 20349849

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11.26.2007 at 06:08AM PST, ID: 20349864

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628