Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Newbie Question.

Status
Not open for further replies.

kgaard

Programmer
Nov 23, 2003
18
US
Hi... I swear I'm going nuts.

I have this line:
echo "<form method=\"post\"><textarea name=\"event1_headline\" cols=25 rows=1 wrap=\"virtual\">";

but i need to add $month.$day.$year. in front of the event1_headline

I'm not sure if I'm having syntax problems, or if I'm just doing something blatantly wrong but I get an error everytime, and i think I've tried every possible solution but the correct one... any help? thanks in advance!
 
I'd probably do:

echo '<form method="post"><textarea name="' . $month . $day . $year . event1_headline . '" cols=25 rows=1 wrap="virtual">';




Want the best answers? Ask the best questions!

TANSTAAFL!!
 
ok, similar question - I'm trying to write to a txt file and im having syntax issues with the file location line:

$filelocation = $month.$day.$year.'event1_details.txt';

I want it to call a txt file such as: 080305event1_details.txt

clearly im not doing something right.
 
I copied your code, and ran it and it works fine.


Where are you getting the values for $day, $month, and $day from maybe there is something wrong there.
What error is it giving you???
 
its actually not giving me an error - but it is reading the file: event1_details.txt NOT 080305event1_details.txt

$filelocation = $month.$day.$year.'event1_details.txt';

the month, day, and year are coming thought just fine from the form before - I echoed them on a previous line and they showedup as expected.

any ideas?

 
then it might be a problem with how your opening the file. if the concatenation is working, and the $filelocation variable contains the correct file name, i.e 080305event1_details.txt then the problem resides in where you open the file. Not where you create the filename.

Could you post your code to open the file so we can take a look at it?

 
surely. also, its began kicking back this:
Warning: fread(): Length parameter must be greater than 0. in /home/u1/kgaard/html/testing/works.php on line 48

it works ok with the first section, but when i copy and paste it again the error occurs. thanks for all your help - sorry, i'm kinda new at this.


<?PHP
$month = $_POST['month'];
$day = $_POST['day'];
$year = $_POST['year'];
if ($_POST['mode']!="") {$mode=$_POST['mode'];}else{$mode=$_GET['mode'];}
$event1_details=$_POST['event1_details'];
$filelocation = $month.$day.$year.'event1_details.txt';
if (!file_exists($filelocation)) {
echo "Error! Couldn't find this date's file, please contact administrator!";
}
else {
$newfile = fopen($filelocation,"r");
$content = fread($newfile, filesize($filelocation));
fclose($newfile);
}
$content = stripslashes($content);
$content = htmlentities($content);
$pass="edit";
if (!$mode || $mode != $pass){
$content = nl2br($content);
echo $content;
}
else {
if ($event1_details){
$event1_details = stripslashes($event1_details);
$newfile = fopen($filelocation,"w");
fwrite($newfile, $event1_details);
fclose($newfile);
echo "Event Details Were Saved.<form><input type=\"submit\" value=\"confirm changes\"></form>";
}
else{
print 'Please Enter Event 1 Details';
echo "<form method=\"post\">
<textarea name=\"event1_details\" cols=50 rows=15 wrap=\"virtual\">";
echo'&details1=';
echo $content;
echo "</textarea><input type=\"hidden\" name=\"mode\" value=\"$pass\"><br><input type=\"submit\" value=\"SAVE\"></form>";
}}

if ($_POST['mode']!="") {$mode=$_POST['mode'];}else{$mode=$_GET['mode'];}
$event1_headline=$_POST['event1_headline'];
$filelocation1 = $month.$day.$year.'event1_headline.txt';
if (!file_exists($filelocation1)) {
echo "Error! Couldn't find this date's file, please contact administrator!";
}
else {
$newfile1 = fopen($filelocation1,"r");
$content1 = fread($newfile1, filesize($filelocation1));
fclose($newfile1);
}
$content1 = stripslashes($content1);
$content1 = htmlentities($content1);
$pass="edit";
if (!$mode || $mode != $pass){
$content1 = nl2br($content1);
echo $content1;
}
else {
if ($event1_headline){
$event1_headline = stripslashes($event1_headline);
$newfile1 = fopen($filelocation1,"w");
fwrite($newfile1, $event1_headline);
fclose($newfile1);
echo "Event Details Were Saved.<form><input type=\"submit\" value=\"confirm changes\"></form>";
}
else{
print 'Please Enter Event 1 Details';
echo "<form method=\"post\">
<textarea name=\"event1_headline\" cols=50 rows=15 wrap=\"virtual\">";
echo'&details1=';
echo $content1;
echo "</textarea><input type=\"hidden\" name=\"mode\" value=\"$pass\"><br><input type=\"submit\" value=\"SAVE\"></form>";
}}



?>
 
I looked at you form:

Code:
   echo "<form method=\"post\">
                <textarea name=\"event1_headline\" cols=50 rows=15 wrap=\"virtual\">";
                echo'&details1=';
                echo $content1;
                echo "</textarea><input type=\"hidden\" name=\"mode\" value=\"$pass\"><br><input type=\"submit\" value=\"SAVE\"></form>";

This forms sends a textarea, and a hidden value. These are sent in the variables $_POST['event1_headline'], and $_POST['mode'] but I see no place where it sends back a day
a month and a year into the $_POST variable. That is to say I have no idea where
Code:
$month = $_POST['month'];
$day = $_POST['day'];
$year = $_POST['year'];
is coming from.
Where are you getting your date values from??? Are you asigning them somewhere else?
Specifically where is $_POST['month'] $_POST['day']$_POST['year'], being sent from??? Obviously not from the form at the bottom.
 
$month = $_POST['month'];
$day = $_POST['day'];
$year = $_POST['year'];

come from a form prior to this page where a user selects the date's events they'd like to edit - then this page will call the txt files associated with that date and display the contents of them into a txtarea so they can be edited, once edited, the textarea saves back to the original .txt file (which is what the form thats on this page is)

still killin me with this fread value error.. agh!
 
So the values for $month, $day, and $year, come from a prior form, are you resending the values when the user submits the second form???? Are the values coming out of $_POST[''] valid??? $_POST['month'] is 08 or something similar??
The values sent from the previous form do not get resent through the next form, you need to catch them, and resend them.

The fread error, is happening because since it cant find the file, it cant get a valid filesize for it. Once it finds the correct file the error should dissapear.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top