Jump to content

Information storage


prcollin

Recommended Posts

Is there anyway to write information from a form to a text document and be able to pull it out of the text document when you want.

 

 

Basically someone fills out a form, the form submits to a text file and i have my own form that is made to search that file. 

Link to comment
Share on other sites

Mysql would be the best way to do it, but if you want to use files...

 

<?php
//Get info from the file
$info = file_get_contents('file.txt');

//Here you can do whatever you want to the info you got

//Write it back to the file
$fh = fopen('file.txt', 'w');
fwrite($fh, $info);
$fclose($fh);
?>

Link to comment
Share on other sites

Tell me what is wrong

Connect.php

 

 

<?php

 

$dbsettings = array(

"servername" => "localhost",

"username" => "pr******llin",

"password" => "n*********",

"dbname" => "prcblog_n*****ers");

 

 

$dbh=mysql_connect ("localhost", "prcblog*****lin", "******") or die ('I cannot connect to the database because: ' . mysql_error());

mysql_select_db ("prcblog_n*********rs");

?>

 

<?php

include "connect.php";

include "connect.css";

 

//then we make the connect() function

 

$dbcon=connect($dbsettings['servername'],$dbsettings['username'],$dbsettings['password'],$dbsettings['dbname']);

 

function connect($server,$user,$pass,$dbname) {

  $dbconn = mysql_connect($server, $user, $pass) or die(mysql_error());

  $select = mysql_select_db($dbname, $dbconn) or die(mysql_error());

  return $select;

 

}

 

 

 

 

//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 = 30></td>\n";

$display .= "</tr>\n\n";

$display .= "<td align = \"right\">Address:</td>\n";

$display .= "<td><input type = \"text\" name = \"address\" size = 20 maxlength = 64></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 = 30></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 = 30></td>\n";

$display .= "</tr>\n\n";

$display .= "<td align = \"right\">Phone Number:</td>\n";

$display .= "<td><input type = \"text\" name = \"phone\" size = 20 maxlength = 30></td>\n";

$display .= "</tr>\n\n";

$display .= "<td align = \"right\">Fax:</td>\n";

$display .= "<td><input type = \"text\" name = \"fax\" size = 20 maxlength = 30></td>\n";

$display .= "</tr>\n";

$display .= "<td align = \"right\">E-mail Address:</td>\n";

$display .= "<td><input type = \"text\" name = \"email\" size = 20 maxlength = 30></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 = 30></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 = 30></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 = 64></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 = 64></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 = 100></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 = 30></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);

$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]);

 

 

$query = mysql_query("INSERT * INTO sign_up (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());

 

$result = mysql_query($query) or die(mysql_error());

 

;

} //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>

 

Link to comment
Share on other sites

Well, for starters. Your using some wierd quotes. These ...

 

$show_form = “yes”;

 

Sould be...

 

$show_form = 'yes';

 

Better still. Take a look at using booleens.

 

Also, your trying to connect twice. Once in the connect.php include (this should be sufficient) and again with your connect() function, which by the way is foo bared. Should be...

 

function connect($server,$user,$pass,$dbname) {
   $dbconn = mysql_connect($server, $user, $pass) or die(mysql_error());
   $select = mysql_select_db($dbname, $dbconn) or die(mysql_error());
  return $dbconn;

}

 

But you dont really even need it.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.