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
https://forums.phpfreaks.com/topic/180783-form-to-php-file/
Share on other sites

look up my post here:-

http://www.phpfreaks.com/forums/index.php/topic,276108.0.html

 

with minor mods, you can write what you need to write to any file, you name it.

 

i would suggest you make sure you make the script go to a new file name each time it executes or it'll over write the same file each time.

 

 

Link to comment
https://forums.phpfreaks.com/topic/180783-form-to-php-file/#findComment-953884
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
https://forums.phpfreaks.com/topic/180783-form-to-php-file/#findComment-954264
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.