submit data to db with html form....(help)
Hi there,
I have the book beginning php 5 and i'm trying to make a site where i can collect data from customers using an html form, i made a few changes to the script in the book to accomodate my own layout but when i press submit nothing happens, it just clears the form and no data is submitted. Can you tell me if you will, what could be wrong with this code?
<?php
include_once "../common_db.inc";
function in_use($username)
{
global $user_tablename;
$query = "SELECT username FROM $user_tablename WHERE username = '$username'";
$result = mysql_query($query);
if(!mysql_num_rows($result)){
return 0;
}else{
return 1;
}
}
function register_form()
{
global $plan;
global $PHP_SELF;
$link_id = db_connect();
mysql_select_db("newsite");
$position_array = enum_options('plan', $link_id);
mysql_close($link_id);
?>
<style type="text/css">
<!--
.style2 {font-style: italic}
.style3 {color: #FF0000}
.style5 {color: #FF0000; font-style: italic; }
-->
</style>
<CENTER><H3>Create a New Account!</H3></CENTER>
<FORM METHOD="POST" ACTION="<?php echo $PHP_SELF ?>">
<INPUT TYPE="HIDDEN" NAME="action">
<DIV ALIGN="CENTER"><TABLE WIDTH="60%" BORDER="1" bordercolor="#0000FF" bgcolor="#99FFFF">
<TR>
<TH WIDTH="30%" NOWRAP>Username</TH>
<TD WIDTH="70%"><INPUT TYPE="TEXT" NAME="username" SIZE="8" MAXLENGTH="8"></TD>
</TR>
<TR>
<TH WIDTH="30%" NOWRAP>Userpassword</TH>
<TD WIDTH="70%"><INPUT TYPE="PASSWORD" NAME="userpassword" SIZE="8" MAXLENGTH="8"></TD>
</TR>
<TR>
<TH WIDTH="30%" NOWRAP>Retype password</TH>
<TD WIDTH="70%"><INPUT TYPE="PASSWORD" NAME="userpassword2" SIZE="8" MAXLENGTH="8"></TD>
</TR>
<TR>
<TH WIDTH="30%" NOWRAP>Full Name</TH>
<TD WIDTH="70%"><INPUT TYPE="TEXT" NAME="fullname" SIZE="30"></TD>
</TR>
<TR>
<TH WIDTH="30%" NOWRAP>Email</TH>
<TD WIDTH="70%"><INPUT TYPE="text" NAME="email" SIZE="30">
</TD>
</TR>
<TR>
<TH WIDTH="30%" NOWRAP>Street / suburb </TH>
<TD WIDTH="70%"><INPUT TYPE="text" NAME="street" SIZE="30">
</TD>
</TR>
<TR>
<TH WIDTH="30%" NOWRAP>City</TH>
<TD WIDTH="70%"><INPUT TYPE="text" NAME="city" SIZE="30">
</TD>
</TR>
<TR>
<TH WIDTH="30%" NOWRAP>State / Province </TH>
<TD WIDTH="70%"><INPUT TYPE="text" NAME="state" SIZE="30">
</TD>
</TR>
<TR>
<TH WIDTH="30%" NOWRAP>Zip / Postal code </TH>
<TD WIDTH="70%"><INPUT TYPE="text" NAME="zip" SIZE="6">
</TD>
</TR>
<TR>
<TH WIDTH="30%" NOWRAP>Phone / Mobile </TH>
<TD WIDTH="70%"><INPUT TYPE="text" NAME="phone" SIZE="20">
</TD>
</TR>
<TR>
<TH WIDTH="30%" NOWRAP>Chose a Plan</TH>
<TD WIDTH="70%"><SELECT NAME="plan"><OPTION VALUE="Growth">growth</OPTION>
<OPTION VALUE="Vehicle">vehicle</OPTION>
<OPTION VALUE="Bond">bond</OPTION>
</SELECT>
<?php
for($i=0; $i < count($plan_array); $i++) {
if(!isset($plan) && $i == 0) {
echo "<OPTION SELECTED VALUE=\"". $plan_array[$i] .
"\">" . $plan_array[$i] . "</OPTION>\n";
}
else if($plan == $cplan_array[$i]) {
echo "<OPTION SELECTED VALUE=\"". $plan_array[$i] . "\">" .
$plan_array[$i] . "</OPTION>\n";
}
else {
echo "<OPTION VALUE=\"". $plan_array[$i] . "\">" .
$plan_array[$i] . "</OPTION>\n";
}
}
?>
</select></TD>
</TR>
<TR>
<TH WIDTH="30%" NOWRAP><span class="style2">Bank details</span></TH>
<TD WIDTH="70%"><span class="style3"><em>Where you would like to be paid</em></span>
</TD>
</TR>
<TR>
<TH WIDTH="30%" NOWRAP>Name of bank</TH>
<TD WIDTH="70%"><INPUT TYPE="text" NAME="bankname" SIZE="50">
</TD>
</TR>
<TR>
<TH WIDTH="30%" NOWRAP>Name of account</TH>
<TD WIDTH="70%"><INPUT TYPE="text" NAME="accountname" SIZE="50">
</TD>
</TR>
<TR>
<TH WIDTH="30%" NOWRAP>Account number</TH>
<TD WIDTH="70%"><INPUT TYPE="text" NAME="accountnumber" SIZE="50">
</TD>
<TR>
<TH WIDTH="30%" NOWRAP>Sort code</TH>
<TD WIDTH="70%"><INPUT TYPE="text" NAME="sortcode" SIZE="6">
</TD>
</TR>
<TR>
<TH WIDTH="30%" NOWRAP>Swift code</TH>
<TD WIDTH="70%"><INPUT TYPE="text" NAME="swiftcode" SIZE="11">
</TD>
</TR>
<TR>
<TH WIDTH="30%" NOWRAP>ABA Route</TH>
<TD WIDTH="70%"><INPUT TYPE="text" NAME="abaroute" SIZE="9">
</TD>
</TR>
<TR>
<TH WIDTH="30%" NOWRAP><span class="style2">Bank address</span></TH>
<TD WIDTH="70%"><span class="style5">Your banks physical address</span>
</TD>
</TR>
<TR>
<TH WIDTH="30%" NOWRAP>Street</TH>
<TD WIDTH="70%"><INPUT TYPE="text" NAME="bankstreet" SIZE="30">
</TD>
</TR>
<TR>
<TH WIDTH="30%" NOWRAP>Suburb</TH>
<TD WIDTH="70%"><input type="text" name="banksuburb" size="30"></TD>
</TR>
<TR>
<TH WIDTH="30%" NOWRAP>zip / postal code</TH>
<TD WIDTH="70%"><INPUT TYPE="text" NAME="bankzip" SIZE="30">
</TD>
</TR>
<TR>
<TH WIDTH="30%" NOWRAP>State / Province</TH>
<TD WIDTH="70%"><INPUT TYPE="text" NAME="bankstate" SIZE="30">
</TD>
</TR>
<TR>
<TH WIDTH="30%" NOWRAP>Country</TH>
<TD WIDTH="70%"><INPUT TYPE="text" NAME="bankcountry" SIZE="30">
</TD>
</TR>
<TR>
<TH WIDTH="30%" COLSPAN="2" NOWRAP>
<INPUT TYPE="SUBMIT" VALUE="Submit">
<INPUT TYPE="RESET" VALUE="Reset"></TH>
</TR>
</TABLE>
</CENTER></DIV>
</FORM>
<?php
}
function create_account()
{
$username = $_POST['username'];
$fullname = $_POST['fullname'];
$userpassword = $_POST['userpassword'];
$userpassword2 = $_POST['userpassword2'];
$email = $_POST['email'];
$street = $_POST['street'];
$city = $_POST['city'];
$state = $_POST['state'];
$zip = $_POST['zip'];
$phone = $_POST['phone'];
$plan = $_POST['plan'];
$bankname = $_POST['bankname'];
$accountname = $_POST['accountname'];
$accountnumber = $_POST['accountnumber'];
$sortcode = $_POST['sortcode'];
$swiftcode = $_POST['swiftcode'];
$abaroute = $_POST['abaroute'];
$bankstreet = $_POST['bankstreet'];
$banksuburb = $_POST['banksuburb'];
$bankzip = $_POST['bankzip'];
$bankstate = $_POST['bankstate'];
$bankcountry = $_POST['bankcountry'];
global $default_dbname, $user_tablename;
if(empty($username)) {
error_message("Enter your desired username!");
}
if(empty($userpassword)) {
error_message("Enter your desired password!");
}
if(strlen($userpassword) < 4 ) {
error_message("Password too short!");
}
if(empty($userpassword2)) {
error_message("Retype your password for verification!");
}
if(empty($username)) {
error_message("Enter your full name!");
}
if(empty($email)) {
error_message("Enter your email address!");
}
if($userpassword != $userpassword2){
error_message("Your desired password and retyped password mismatch!");
}
$link_id = db_connect($default_dbname);
if(in_use($username)){
error_message("$username is in use. Please choose a different one.");
}
// Insert information into the table "user"
$query = "INSERT INTO user VALUES
(NULL, '$username', '$fullname', password('$userpassword'), '$email', '$street', '$city', '$state',
'$zip', '$phone', '$plan', '$bankname', '$accountname', '$accountnumber', '$sortcode',
'$swiftcode', '$abaroute', '$bankstreet', '$banksuburb', '$bankzip', '$bankstate', '$bankcountry')";
$result = mysql_query($query);
if(!$result) {
error_message(sql_error());
}
$usernumber = mysql_insert_id($link_id);
html_header();
?>
<CENTER><H3>
<?php echo $username ?>, thank you for registering with us!
</H3></CENTER>
<DIV ALIGN="CENTER"><CENTER><TABLE BORDER="1" WIDTH="90%">
<TR>
<TH WIDTH="30%" NOWRAP>username</TH>
<TD WIDTH="70%"><?php echo $usernname ?></TD>
</TR>
<TR>
<TH WIDTH="30%" NOWRAP>fullname</TH>
<TD WIDTH="70%"><?php echo $fullname ?></TD>
</TR>
<TR>
<TH WIDTH="30%" NOWRAP>email</TH>
<TD WIDTH="70%"><?php echo $email ?></TD>
</TR>
<TR>
<TH WIDTH="30%" NOWRAP>state</TH>
<TD WIDTH="70%"><?php echo $state ?></TD>
</TR>
<TR>
<TH WIDTH="30%" NOWRAP>phone</TH>
<TD WIDTH="70%"><?php echo $phone ?></TD>
</TR>
<TR>
<TH WIDTH="30%" NOWRAP>bankname</TH>
<TD WIDTH="70%"><?php echo $bankname ?></TD>
</TR>
</TABLE>
</CENTER></DIV>
<?php
html_footer();
}
if (empty($_POST)) $_POST['action'] = "";
switch($_POST['action']) {
case "register":
create_account();
break;
default:
html_header();
register_form();
html_footer();
break;
}
?>
I would appreciate any help...
Thankyou.
Dislexics have more fnu
|