Jump to content

[SOLVED] Won't pick up variable


jcbarr

Recommended Posts

Any ideas why this script isn't picking up the $editdraft variable that is being sent via the form at the bottom of the script?

 

<html>
<head>
<title>Draft Admin</title>
</head>
<body><BR><BR><BR><BR><BR>

<center>
<a href=admin.php?CREATE=Y>CREATE DRAFT FILE</a>
<P>
<a href=admin.php?EDIT=Y>EDIT DRAFT FILE</a>
<P>
<?php

//Gather Variables
$create = $_GET['CREATE'];
$edit = $_GET['EDIT'];
$make = $_POST['make'];
$year = $_POST['year'];
$type = $_POST['type'];
$draft = $_POST['draft'];
$editdraft = $_POST['editdraft'];

echo $editdraft;

//Create Draft File Form
if (!empty($create)){
echo <<<END
<b><h2>CREATE DRAFT</h2></b>
<form method="post" action="admin.php">
<input type="hidden" name="make" value="Y">
<input type="text" name="year" value="Type Year Here">
<select name="type"><option value="FA">Free Agent</option>
<option value="AM">Amateur</option>
</select>
<input type="submit" value="Create Draft">

</form>
END;
}

//Create TXT File For Draft
if ($make=="Y"){
$filename = "$year$type";
$ext = ".txt";
fopen("drafts/$filename$ext", "w+");
echo "$filename has been created. Click <a href=admin.php>here</a> to refresh page.";
}


//Make Select Edit Form
if ($edit=="Y"){ ?>
<B><h2>SELECT DRAFT FILE TO EDIT</b></h2> <form name="form1" method="post" action="admin.php"><select name=draft onchange=form1.submit()><option value=''></option>
<?php
$dir = "drafts";
$dh  = opendir($dir);
while (false !== ($filename = readdir($dh))) {
   $files[] = $filename;
}

sort($files);

foreach ($files as $drafts){
if ($drafts !== '.' && $drafts !== '..'){
 	$drafts = substr($drafts, 0, 6);
	echo "<option value='$drafts'>$drafts</option>";
}
}
?>
</select>
</form>


<?php	
}

//Make Edit Form
if (!empty($draft)){
$ext = ".txt";
$filename = "$draft$ext";
$text = file_get_contents("drafts/$filename");
echo <<<END
<form name='form2' method='post' action='admin.php'>
<input type="hidden" name="editdraft" value="$filename">
<TEXTAREA NAME="edit" ROWS=50 COLS=50>$text</TEXTAREA>
<BR>
<INPUT TYPE="reset">
<INPUT TYPE="submit" NAME="submit" VALUE="Submit">
</FORM>
END;
}


//Write To Draft File
if (!empty($editdraft)){
$handle = fopen("$editdraft", "w+");
fwrite($handle, $edit);
fclose($handle);
echo "$editdraft has been edited. Click <a href=admin.php>HERE</a> to refresh page.";
}

?>
</center>

</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/43478-solved-wont-pick-up-variable/
Share on other sites


<?php	
}

//Make Edit Form
if (!empty($draft)){
$ext = ".txt";
$filename = "$draft$ext";
$text = file_get_contents("drafts/$filename");

echo "<form name="form2" method='post' action='admin.php'>";
echo "<input type="hidden" name="editdraft" value="$filename">";
echo "<TEXTAREA NAME="edit" ROWS=50 COLS=50>$text</TEXTAREA>";
echo "<BR>";
echo "<INPUT TYPE="reset">";
echo "<INPUT TYPE="submit" NAME="submit" VALUE="Submit">";
echo "</FORM>";

}


//Write To Draft File
if (!empty($editdraft)){
$handle = fopen("$editdraft", "w+");
fwrite($handle, $edit);
fclose($handle);
echo "$editdraft has been edited. Click <a href=admin.php>HERE</a> to refresh page.";
}

?>

 

You need to sort out the quotes.

 

monk.e.boy

I would check the filename, chances are that is where the error is., I never used the <<<END and END; Try it this way:

 

echo '<form name="form2" method="post" action="admin.php">
<input type="hidden" name="editdraft" value="'.$filename.'">
<TEXTAREA NAME="edit" ROWS=50 COLS=50>$text</TEXTAREA>
<BR>
<INPUT TYPE="reset">
<INPUT TYPE="submit" NAME="submit" VALUE="Submit">
</FORM>';

 

see what happens.

Here is the deal if anyone cares. Apparently it had to do with my browser settings at home. My browser was apparently not loading the page again it was just using a cached version or something like that.

 

I get to work and the thing works without a hitch, so I guess everything is okay now.

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.