Jump to content

Form to PHP File


01hanstu

Recommended Posts

Hi, I am wonder if someone can help.

 

I want to be able to complete a form, the submit it and all of the information will save in a settings.php file.

 

i.e. company_txt (text field) will save to variable $Company which is set as empty in the

 

setting.php file will look like this (below) just empty until the form has been completed.

 

<?php

&company = "";

&var1= "";

&var2= "";

&var3= "";

?>

 

Thanks

Stuart

Link to comment
Share on other sites

This is a script that i made to make a file called db.php with some mods it will serv your needs

 

 

<?php
$error = false;
if(isset($_POST['Submit'])){
if($_POST['host'] =="") {
echo"Please Fill Out the Host Filed";
$error = true;
}
if($_POST['user'] =="") {
echo"<br>Please fill Out the Username Filed";
$error = true;
}
if($_POST['pass'] =="") {
echo"<br>Please Fill Out the Password";
$error = true;
}
if($_POST['db_name'] =="") {
echo"<br>please fill Out the Databases name";
$error = true;
}

if ($error){
exit();
}

$db_host=$_POST['host'];
$db_user=$_POST['user'];
$db_pass=$_POST['pass'];
$db_dbname=$_POST['db_name'];
$file = 'db.php';
$host = '$host=" '.$db_host .' ";' ."\n";
$user = '$user="'. $db_user .' ";' ."\n";
$pass = '$pass=" '. $db_pass .' ";' ."\n";
$db_name = '$$db_name="'. $db_dbname .' ";' ."\n";
$query ='$link = mysql_connect($host, $user, $pass);' ."\n";
$db = 'mysql_select_db($db_name);' ."\n";

file_put_contents($file, $host);
file_put_contents($file, $user, FILE_APPEND);
file_put_contents($file,$pass, FILE_APPEND);
file_put_contents($file,$db_name, FILE_APPEND);
file_put_contents($file,$query, FILE_APPEND);
file_put_contents($file,$db, FILE_APPEND);

echo"File Done <br> $db_host";
}
else
{
echo"<form name='form1' method='post' action=''>

<table width='259' height='192' border='1' align='center'>
  <tr>
    <td colspan='2'>Data Base Conntection </td>
  </tr>
  <tr>
    <td width='140'>Host</td>
    <td width='103'><label>
      <input type='text' name='host' id='host'>
    </label></td>
  </tr>
  <tr>
    <td>Username</td>
    <td><label>
      <input type='text' name='user' id='usern'>
    </label></td>
  </tr>
  <tr>
    <td>Password</td>
    <td><label>
      <input type='text' name='pass' id='pass'>
    </label></td>
  </tr>
  <tr>
    <td>Database Name</td>
    <td><label>
      <input type='text' name='db_name' id='db_name'>
    </label></td>
  </tr>
  <tr>
    <td colspan='2' align='center'><label>
      <input type='submit' name='Submit' id='Submit' value='Submit'>
    </label></td>
  </tr>
</table>
<form name='form1' method='post' action=''>
</form>";
}
?>


 

Enjoy

 

bob

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.