Advertisement
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.
Your Input Matters 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! |
||
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> </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 );");
}
|