Jump to content

almost connect but not quite. Need help


prcollin

Recommended Posts

I have a form that i am trying to post to a database in my phpmyadmin mysql account.  I have it so that the form appears but when you fill out the form and submit it hte for just resets and nothing posts to the database, i dont get any password or database connection errors. 

 

 

shold this code be in the form if i want it to post to a database

 

$display .= "<form action = \"$_SERVER

[php_SELF]\" method = \"post\">\n";

here is the whole code for the login_form.php file

<?php

include("connect.php");

//first check to see if user submits
if (!isset($_POST[submit])) {
//if the submit button is not pushed, show the form
$show_form = "yes";
} elseif (isset($_POST[submit])) {
//if the submit button is pushed, check errors
if (empty($_POST[username])) {
;
//show the form
$show_form = "yes";
//…and so on with the errors
} else {
//after no more error checks, if user passes all
$show_success = "yes";
} //end if
} //end if  ->you can put if statements inside if statements

//if show form is true …then display it
if ($show_form == "yes") {
$display = "<center>\n";
$display .= "$error\n";
$display .= "<form action = \"$_SERVER[php_SELF]\" method = \"post\">\n";
$display .= "<table border = >\n";

$display .= "<td align = \"right\">Company Name:</td>\n";
$display .= "<td><input type = \"text\" name = \"company_name\" size
= 20 maxlength = 50></td>\n";
$display .= "</tr>\n\n";
$display .= "<td align = \"right\">Address:</td>\n";
$display .= "<td><input type = \"text\" name = \"address\" size = 20
maxlength = 50></td>\n";
$display .= "</tr>\n\n";
$display .= "<td align = \"right\">City:</td>\n";
$display .= "<td><input type = \"text\" name = \"city\" size = 20
maxlength = 50></td>\n";
$display .= "</tr>\n\n";
$display .= "<td align = \"right\">State:</td>\n";
$display .= "<td><input type = \"text\" name = \"state\" size = 20
maxlength = 50></td>\n";
$display .= "</tr>\n\n";
$display .= "<td align = \"right\">Zip Code:</td>\n";
$display .= "<td><input type = \"text\" name = \"zip_code\" size =
20 maxlength = 50></td>\n";
$display .= "</tr>\n\n";
$display .= "<td align = \"right\">Phone Number:</td>\n";
$display .= "<td><input type = \"text\" name = \"phone\" size = 20
maxlength = 50></td>\n";
$display .= "</tr>\n\n";
$display .= "<td align = \"right\">Fax:</td>\n";
$display .= "<td><input type = \"text\" name = \"fax\" size = 20
maxlength = 50></td>\n";
$display .= "</tr>\n";
$display .= "<td align = \"right\">E-mail Address:</td>\n";
$display .= "<td><input type = \"text\" name = \"email\" size = 20
maxlength = 50></td>\n";
$display .= "</tr>\n\n";
$display .= "<td align = \"right\">Chose a User Name:</td>\n";
$display .= "<td><input type = \"text\" name = \"user_name\" size =
20 maxlength = 50></td>\n";
$display .= "</tr>\n\n";
$display .= "<td align = \"right\">Choose  A Password:</td>\n";
$display .= "<td><input type = \"password\" name = \"password\" size
= 20 maxlength = 50></td>\n";
$display .= "</tr>\n\n";
$display .= "<td align = \"right\">Re-Type Password:</td>\n";
$display .= "<td><input type = \"password\" name = \"pass2\" size =
20 maxlength = 50></td>\n";
$display .= "</tr>\n\n";
$display .= "<td align = \"right\">Type A Security Question:</td>\n";
$display .= "<td><input type = \"text\" name = \"security_question\"
size = 20 maxlength = 50></td>\n";
$display .= "</tr>\n\n";
$display .= "<td align = \"right\">Type A Security Question Answer:</td>\n";
$display .= "<td><input type = \"text\" name =
\"security_questionans\" size = 20
maxlength = 50></td>\n";
$display .= "</tr>\n\n";
$display .= "<td align = \"right\">Please Choose a Subdomain Name:</td>\n";
$display .= "<td><input type = \"text\" name = \"subdomain_choice\"
size = 20 maxlength = 50></td>\n";
$display .= "</tr>\n\n";
$display .= "<td align = \"right\">Please choose a business category:</td>\n";
$display .= "<td><input type = \"text\" name = \"category\"
size = 20 maxlength = 50></td>\n";
$display .= "<td><input type = \"submit\" name = \"submit\" value =
\"Register\"></td>\n";
$display .= "</tr>\n";
$display .= "</table>\n";
$display .= "</form>\n";
$display .= "</center>\n";
} //if

if ($show_success == "yes") {

$company_name = ($_POST[company_name]);
$address = ($_POST[address]);
$city = ($_POST[city]);
$state = ($_POST[state]);
$zip_code = ($_POST[zip_code]);
$phone = ($_POST[phone]);
$fax = ($_POST[fax]);
$email = ($_POST[email]);
$user_name = ($_POST[user_name]);
$password = ($_POST[password]);
$pass2 = ($_POST[pass2]);
$security_question = ($_POST[sercurity_question]);
       $security_questionans = ($_POST[security_questionans]);
$subdomain_choice = ($_POST[subdomain_choice]);
$category_type = ($_POST[category]);


$query = mysql_query("INSERT INTO clients (companyName, address, city,
state, zipeCode, phone, fax, eMail, userName, passWord,
retypePassword, securityQuestion, subDomain)

VALUES ('$company_name', '$address', '$city', '$state', '$zip_code',
'$phone', '$fax', '$email', '$user_name', '$password', '$pass2',
'$security_question', '$security_questionans',
'$subdomain_choice')")or die(mysql_error());


//then display a success message
;
} //end if

?>
<html>
<head>
<title>New Customer Sign Up Form</title>
</head>
<body>
<h3>New Customer Sign Up Form</h3>
<p><?php print "$display"; ?></p>

</body>
</html>

 

here is my connect.php file

 

<?php
$dbhost = 'localhost';
$dbuser = 'prcblog_*******';
$dbpass = 'n*******';
$dbname = 'prcblog_clients';

$link = mysql_pconnect($dbhost, $dbuser, $dbpass)
or die("Could not connect to server.");
$selectdb = mysql_select_db($dbname, $link)
or die("Could not connect to database.");
?>

I left the name of the database. and the table that i am trying to get it to post to is "newclients"

please see if you see anything wrong with my script

Link to comment
https://forums.phpfreaks.com/topic/60458-almost-connect-but-not-quite-need-help/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.