Form question

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
daedalus__
DevNet Resident
Posts: 1925
Joined: Thu Feb 09, 2006 4:52 pm

Post by daedalus__ »

I want to see the entire script.
User avatar
akimm
Forum Contributor
Posts: 460
Joined: Thu Apr 27, 2006 10:50 am
Location: Ypsilanti Michigan, formally Clipsburgh

code

Post by akimm »

program form:

Code: Select all

<form action="journalbox.php" method="POST">
<p><b>Date</b>
<input type="text" value="<?php echo date("F j, Y, g:i a");?>" name="date" size="30"></p>

<p><b>Mood</b>
<select name="mood">
<option value="apathetic">apathetic
<option value="overjoyed">overjoyed
<option value="inquisitive">inquisitive
<option value="outlandish">outlandish
<option value="appreciative">appreciative
<option value="confused">confused
<option value="displeased">displeased
<option value="disgruntled">disgruntled
<option value="sick">sick
<option value="terrified">terrified
<option value="mental">mental
<option value="eruditic">eruditic
<option value="forlorn">forlorn
<option value="convuluted">convuluted
<option value="ingenious">ingenious
<option value="arrogant">arrogant
<option value="free">free
<option value="stupid">stupid
<option value="moronic">moronic
<option value="pointless">pointless
</select>

<?php
$smile = array('2guns', 'somethingElse');

/**
 * This generates a drop down with
 * the array index as the key and
 * the smilie name as the value in the form
 **/
echo '<select name="smile">';
foreach ($smile as $key => $value)
{
    echo '<option value="' . $key . '">' . $value . '</option>';
}
?>

<select name="smile">

<?php
$img_id = $_POST['smile'];
echo '<img src="/journal06/smile/' . $smile[$img_id] . '.gif" />';
?>
</select>

<p><b>entry</b>
<TEXTAREA NAME="entry" COLS="80" ROWS="5" WRAP="virtual"></TEXTAREA></P>

<p><input type="submit" name="submit" value="send your entry!"></p>
</form>
journalbox.php

Code: Select all

<?php
$filename = "journalaug_sept.txt";
$handle = fopen($filename, 'a');
$write_string = $_POST['date'] . "<font family=arial>" . "<BR>" . "<BR>";
$write_string .= $_POST['mood'] . $_POST['smile'] . $smile[$img_id] . "<font family=arial>" . "<BR>" . "<BR>";
$write_string .= $_POST['entry'] . "<font family=arial>" . "<BR>" . "<BR>";
$write_string .= "<HR NOSHADE SIZE=4 COLOR=BLUE>";

fwrite($handle, $write_string);
	fclose($handle);
?>
journal.php

Code: Select all

<?php
include('journalread.php')
?>
journalread.php

Code: Select all

<?php
$myFile = "journalaug_sept.txt";
$fh = fopen($myFile, 'r');
$theData = fread($fh, filesize($myFile));
fclose($fh);
echo $theData;
?>
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Re: code

Post by RobertGonzalez »

Try this...
program form:

Code: Select all

<form action="journalbox.php" method="POST">
<p><b>Date</b>
<input type="text" value="<?php echo date('F j, Y, g:i a');?>" name="date" size="30"></p>

<p><b>Mood</b>
<select name="mood">
<option value="apathetic">apathetic
<option value="overjoyed">overjoyed
<option value="inquisitive">inquisitive
<option value="outlandish">outlandish
<option value="appreciative">appreciative
<option value="confused">confused
<option value="displeased">displeased
<option value="disgruntled">disgruntled
<option value="sick">sick
<option value="terrified">terrified
<option value="mental">mental
<option value="eruditic">eruditic
<option value="forlorn">forlorn
<option value="convuluted">convuluted
<option value="ingenious">ingenious
<option value="arrogant">arrogant
<option value="free">free
<option value="stupid">stupid
<option value="moronic">moronic
<option value="pointless">pointless
</select>
<br /><br />
<select name="smile">
<?php
$smile = array('2guns', 'somethingElse');

/**
 * This generates a drop down with
 * the array index as the key and
 * the smilie name as the value in the form
 **/
foreach ($smile as $key => $value)
{
    echo '<option value="' . $key . '">' . $value . '</option>';
}
?>
</select>

<p><b>entry</b>
<TEXTAREA NAME="entry" COLS="80" ROWS="5" WRAP="virtual"></TEXTAREA></P>

<p><input type="submit" name="submit" value="send your entry!"></p>
</form>
journalbox.php

Code: Select all

<?php
$smile = array('2guns', 'somethingElse');

$img_id = $_POST['smile'];
echo '<img src="/journal06/smile/' . $smile[$img_id] . '.gif" />';

$filename = "journalaug_sept.txt";
$handle = fopen($filename, 'a');
$write_string = $_POST['date'] . "<font family=arial>" . "<BR>" . "<BR>";
$write_string .= $_POST['mood'] . $_POST['smile'] . $smile[$img_id] . "<font family=arial>" . "<BR>" . "<BR>";
$write_string .= $_POST['entry'] . "<font family=arial>" . "<BR>" . "<BR>";
$write_string .= "<HR NOSHADE SIZE=4 COLOR=BLUE>";

fwrite($handle, $write_string);
	fclose($handle);
?>
journal.php

Code: Select all

<?php
include('journalread.php')
?>
journalread.php

Code: Select all

<?php
$myFile = "journalaug_sept.txt";
$fh = fopen($myFile, 'r');
$theData = fread($fh, filesize($myFile));
fclose($fh);
echo $theData;
?>
User avatar
akimm
Forum Contributor
Posts: 460
Joined: Thu Apr 27, 2006 10:50 am
Location: Ypsilanti Michigan, formally Clipsburgh

Everah

Post by akimm »

That code is still not the right solution, i even checked the textfile to see if it had been written, but no luck.
User avatar
akimm
Forum Contributor
Posts: 460
Joined: Thu Apr 27, 2006 10:50 am
Location: Ypsilanti Michigan, formally Clipsburgh

ok

Post by akimm »

So is there no way to actually do this by means of flatfile? Will I need to incoperate some MYSQL DB's or another DB to make this possible?
Post Reply