i want to place the contents of values from a form into a text file. When an option is changed in the form and submit button is clicked, the user is taken to another page where info about the company's address, website and so are displayed line after line like so:

Member Search Results:

Company
800-555-555
Address Line 1
Address Line 2
Website: http://example.com

Though the text file shows up blank. How do i go about achieving my desired result?

My code i tried originally:

<html>
<form action="http://*****.com/business_detail_framed.asp" method="post" name="b1">
<Select Name="select_business" onChange="b1.input1.value=b1.select_business[this.selectedIndex].text">
<option value="5102" name="float">Company One</option>
<option value="5053" name="float">Company Two</option>
<option value="5091" name="float">Company 3</option>
</select>
<input value="Submit" type="submit" onchange="this.form.submit()">;
</form>

<?php

file_put_contents("businessinfo.txt", $_POST['float'], FILE_APPEND);

$g = file_get_contents("businessinfo.txt");
echo $g;

$r = $_REQUEST['float'];
$r .= $_POST['float'];

echo $r;

?>

And the code i tried with a little help, but still no luck, the text file still shows up empty:

if (isset($_REQUEST['Submit'])) {
  file_put_contents("businessinfo.txt", $_REQUEST['select_business'] . "\n", FILE_APPEND);

Any suggestions?

Have you checked your file permissions? The file needs to be writable by the server.
chown apache businessinfo.txt
chmod 644 businessinfo.txt

R.

Yes the permissions are fine. I checked them.

Have you tried using $_POST instead of $_REQUEST?

Have you tried using $_POST instead of $_REQUEST?

I did, still not seeing any results.

If you're still using this code it won't work, because you've not included the name attribute on the submit variable.

if (isset($_REQUEST['Submit']))
    file_put_contents("businessinfo.txt", $_REQUEST['select_business'] . "\n", FILE_APPEND);

IT should be noted that the form action is linked to a .asp file that sets the connection to a database that holds these records and displays them in a certain format. I am able to see these records by clicking the submit button, but i need to extract the data to a text file. I just included 3 options in the form as a test for the rest of the process. The contents of the .asp file is here if you need to see it. http://pastebin.com/BSUqBX8k

I hadn't noticed the form action before. If the page isn't submitting to itself, and the PHP code to write to the text file is included in the same file as the form, how are you expecting it to write to the file?

It'll only get to that code when $_POST isn't set, i.e. when loading the page.

I posted this somewhere else as well, and someone told me that if the form isn't submitting to itself, the $_POST variables won't really get that info. Is this what you're saying?

Yes. It doesn't need to necessarily post to itself. But the post variables are only set after form submission.

Yes. It doesn't need to necessarily post to itself. But the post variables are only set after form submission.

So all in all what should i do?

Write to the file in your ASP script or execute your queries in the PHP script.

Write to the file in your ASP script or execute your queries in the PHP script.

I actually heavily considered that, but i do not know where to start off on doing that, as i didn't originally write the ASP script, and i know nothing much about the language.
But the main problem extends from the fact that the data is on a remote database the login info for that is lost.

If the ASP script is accessing the database, then the database credentials must be contained within the script somewhere.

R.

Apparently it's not there either, i had someone with experience in ASP take a look at the script and they dont see the database credentials either, the only indication of database connection is where it says ADODB.Connection

well i guess your question must be "Extract text from a text file to form" i don't know i'm little bit confuse :?. by the way if your using php to extract data from an asp script i think you should include this to your

<input type= ... name= "submit">

try using $_POST so that if the button is clicked it will fetch the data. as far as i can understand your problem , i think you need to use

session_start();
$_SESSION['submit'] = $_POST['submit']; 
session_close();

so that you can use it in different script/page.
try using fwrite(for writing strings to a textfile or any file) or fread(to read a text or any files) it's much easier just a suggestion.

Tried it this way

<html>
<form action="http://*********.com/business_detail_framed.asp" method="post" name="b1">
<select name="select_business" >
<option value="5102" name="float">1 Stop Signs</option>
<option value="5053" name="float">23/6 Services, LLC</option>
<option value="5091" name="float">A Touch Above</option>
</select>
<input value="Submit" type="submit" onchange="this.form.submit()">;
</form>

<?php

session_start();
$_SESSION['submit'] = $_POST['submit']; 
  file_put_contents("businessinfo.txt", $_POST['select_business'] . "\n", FILE_APPEND);
session_close();

?>
</html>

Still the data isn't being written to the file. Also fopen, fwrite essentially does the same thing as file_put_contents.

Maybe exploring the route of including asp function sin the actual asp file in the pastebin link i included that will write the records to the file. Anybody have some asp experience with that?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.