Closed Thread Icon

Topic awaiting preservation: PHP form updater... need help Pages that link to <a href="https://ozoneasylum.com/backlink?for=22775" title="Pages that link to Topic awaiting preservation: PHP form updater... need help" rel="nofollow" >Topic awaiting preservation: PHP form updater... need help\

 
Author Thread
redroy
Nervous Wreck (II) Inmate

From: 1393
Insane since: Dec 2003

posted posted 08-02-2004 17:35

I'm a newbie with PHP and I need a quick and easy way to build an online form that will update the contents of another pages table cells... would this be difficult? Basically it's just a table with five columns with text and the last cell being a link. I would like to write a PHP script that adds another row with the inputed information from a form. Will be willing to pay if needed.

70% of statistics are made up on the spot.

DL-44
Maniac (V) Inmate

From: under the bed
Insane since: Feb 2000

posted posted 08-02-2004 18:01

That should be pretty simple.

The big questions are -

How much information are we talking about here? This sounds like a perfect example of a job for a database, but you could also go with storing the info in a .txt file or some other such setup.

How many people will be using this form? This will determine what kind of security and user authentication (if any) you will need. That is where things can get a little more complicated.

bitdamaged
Maniac (V) Mad Scientist

From: 100101010011 <-- right about here
Insane since: Mar 2000

posted posted 08-02-2004 18:08

For a quick and dirty solution all I would do is maintain a text file with the rows if information. Then use that to create the table, with each row in the text file corresponding to the rows in the table.

So you take your input field data from the $_POST or $_GET variables.

Then just create an array from those like so

code:
$array[0] = $_POST['someformvariable1'];
$array[1] = $_POST['someformvariable2'];
$array[2] = $_POST['someformvariable3'];
$array[3] = $_POST['someformvariable4'];
$array[4] = $_POST['someformvariable5'];


then use implode with some seperator to create a single line from the array.

Then use fwrite (look at the documentation for usage) to write append a new line to the text file.

Then when you want to create your table, you use file to load the file into an array by lines, loop through each line and use explode to get a temp array with your data which you write out.

Pretty easy stuff.



.:[ Never resist a perfect moment ]:.

(Edited by bitdamaged on 08-02-2004 18:08)

redroy
Nervous Wreck (II) Inmate

From: 1393
Insane since: Dec 2003

posted posted 08-02-2004 20:20

bitdamaged, that's what i'm looking for. I see what you're saying. I've read throught the different links and I understand the process but I'm still confused as how to actually set it up. The only work i've done with PHP is just manipulating other's scripts...

So I would have one html page with the form, one txt file to hold the data, one php file to handle the operations, and another html file to show the output...? How hard would it be to make a quick example for me?

70% of statistics are made up on the spot.

redroy
Nervous Wreck (II) Inmate

From: 1393
Insane since: Dec 2003

posted posted 08-02-2004 22:03

Alright... I think I may be somewhat close... I don't have access to the server with PHP on it right now so I was hoping you could look this over and see what the heck I'm doing.

page with form to gather info:

code:
<form action="go-update-standard.php" method="post" name="standard">
File Name:<br>
<input name="file-name" type="text" size="25"><br>
Description:<br>
<textarea name="description" cols="25" rows="5"></textarea><br>
Last Updated:<br>
<input name="last-updated" type="text" size="25"><br>
REV #:<br>
<input name="rev" type="text" size="25"><br>
Path to file:<br>
<input name="path" type="text" size="25"><hr class="hr1">
<input name="submit" type="submit" value="Submit"> <input name="reset" type="reset" value="Reset">
</form>


go-update-standard code:

code:
<?
$array[0] = $_POST['file-name'];
$array[1] = $_POST['description'];
$array[2] = $_POST['last-updated'];
$array[3] = $_POST['rev'];
$array[4] = $_POST['path'];

$array = array('file-name', 'description', 'last-updated', 'rev', 'path');
$comma_separated = implode(",", $array);

$filename = 'standard-lisps.txt'
if (is_writable($filename))
if (!$handle = fopen($filename, 'a')) {
echo "Cannot open file ($filename)";
exit;
}
if (fwrite($handle, $comma_separated) === FALSE) {
echo "Cannot write to file ($filename)";
exit;
}

echo "Success, wrote ($comma_separated) to file ($filename)";

fclose($handle);

} else {
echo "The file $filename is not writable";
}
?>



page to display info:

code:
<table class="lisps" cellpadding="0" cellspacing="0">
<tr>

<td>File Name</td><td>Description</td><td>Last Updated</td><td>REV#</td><td>&nbsp;</td>

</tr>
<?php
$lines = file('standard-lisps.txt');
foreach ($lines as $line_num => $line) {
$pieces = explode(" ", $lines);
echo "<tr><td>{$pieces[0]}</td><td>{$pieces[1]}</td><td>{$pieces[2]}</td><td>{$pieces[3]}</td><td>{$pieces[4]}</td></tr>"
}
?>
</table>



Thanks for all your help.

70% of statistics are made up on the spot.

bitdamaged
Maniac (V) Mad Scientist

From: 100101010011 <-- right about here
Insane since: Mar 2000

posted posted 08-03-2004 01:34

That looks about right.

this bit:

code:
$array[0] = $_POST['file-name'];
$array[1] = $_POST['description'];
$array[2] = $_POST['last-updated'];
$array[3] = $_POST['rev'];
$array[4] = $_POST['path'];

$array = array('file-name', 'description', 'last-updated', 'rev', 'path');



is a bit screwy. You just need this:

code:
$array = array();
$array[0] = $_POST['file-name'];
$array[1] = $_POST['description'];
$array[2] = $_POST['last-updated'];
$array[3] = $_POST['rev'];
$array[4] = $_POST['path'];



(oh and my bad, don't name variables "array" you'll kick yourself at sompoint wondering why ( $array = $array() ) doesn't work

This line is also a bit off:

code:
foreach ($lines as $line_num => $line) { ..



You don't need the "=>" operator on an array that's not associative, all you need is

code:
foreach ($lines as $line) {



Then explode the line ($line not $lines)

code:
$pieces = explode(" ", $line);







.:[ Never resist a perfect moment ]:.

(Edited by bitdamaged on 08-03-2004 01:37)

redroy
Nervous Wreck (II) Inmate

From: 1393
Insane since: Dec 2003

posted posted 08-03-2004 03:32

Sweet! Everything is working except it's writing all the entries in the txt file on one line... how do I get it to "bumb" down a line very time an entry is added?

70% of statistics are made up on the spot.

redroy
Nervous Wreck (II) Inmate

From: 1393
Insane since: Dec 2003

posted posted 08-03-2004 04:23

K... I think I got it. I added a '\n' to my array...

code:
$inp = array();
$inp[0] = $_POST['file-name'];
$inp[1] = $_POST['description'];
$inp[2] = $_POST['last-updated'];
$inp[3] = $_POST['rev'];
$inp[4] = $_POST['path'];
$inp[5] = "\n";


It seems to be working fine... is that OK?

70% of statistics are made up on the spot.

H][RO
Bipolar (III) Inmate

From: Australia
Insane since: Oct 2002

posted posted 08-03-2004 04:29

try putting \r\n
if you want to tab something also u can use \t

Skaarjj
Maniac (V) Mad Scientist

From: :morF
Insane since: May 2000

posted posted 08-03-2004 05:32

I'd actually put \n\r, becuase otherwise you'll go back ot the start of the line and *then* go down a line, taking the last line of text with you.

H][RO
Bipolar (III) Inmate

From: Australia
Insane since: Oct 2002

posted posted 08-03-2004 05:44

ahh is that how it works

redroy
Nervous Wreck (II) Inmate

From: 1393
Insane since: Dec 2003

posted posted 08-09-2004 04:52

Sweet, my first php script is alive! Thanks for all the help.

70% of statistics are made up on the spot.

« BackwardsOnwards »

Show Forum Drop Down Menu