Jump to content

[SOLVED] Saving data to text file (I did a search! I swear!)


Styles2304

Recommended Posts

I have a php form that I'm trying to save to a text file to be accessed by flash later on. I'm able to get the text file created but nothing ever writes too it. I have 29 variables that need to be recorded to be accessed later . . . can someone help me out here? Following another tutorial to make sure i had it set up correctly (that's still debatable) here's the form code.

 

<?php
$hosturl = $_POST["hosturl"];

$mtitle1 = $_POST["mtitle1"];
$mimgurl1 = $_POST["mimgurl1"];
$mrate1 = $_POST["mrate1"];
$mreview1 = $_POST["mreview1"];

$mtitle2 = $_POST["mtitle2"];
$mimgurl2 = $_POST["mimgurl2"];
$mrate2 = $_POST["mrate2"];
$mreview2 = $_POST["mreview2"];

$mtitle3 = $_POST["mtitle3"];
$mimgurl3 = $_POST["mimgurl3"];
$mrate3 = $_POST["mrate3"];
$mreview3 = $_POST["mreview3"];

$mtitle4 = $_POST["mtitle4"];
$mimgurl4 = $_POST["mimgurl4"];
$mrate4 = $_POST["mrate4"];
$mreview4 = $_POST["mreview4"];

$mtitle5 = $_POST["mtitle5"];
$mimgurl5 = $_POST["mimgurl5"];
$mrate5 = $_POST["mrate5"];
$mreview5 = $_POST["mreview5"];

$mtitle6 = $_POST["mtitle6"];
$mimgurl6 = $_POST["mimgurl6"];
$mrate6 = $_POST["mrate6"];
$mreview6 = $_POST["mreview6"];

$mtitle7 = $_POST["mtitle7"];
$mimgurl7 = $_POST["mimgurl7"];
$mrate7 = $_POST["mrate7"];
$mreview7 = $_POST["mreview7"];

?>


<html>
<head>
<title>Website Template</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<script type="text/javascript">

function ismaxlength(obj){
var mlength=obj.getAttribute? parseInt(obj.getAttribute("maxlength")) : ""
if (obj.getAttribute && obj.value.length>mlength)
obj.value=obj.value.substring(0,mlength)
}

</script>
</head>
<body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">

<center>

Rate Movies Setup Form
<p>
<font size="2pt">
There is a list of faqs (frequently asked questions) at the bottom of the page in case<br>
you're unfamiliar with some of the terms or processes used on this page. Read those first
before asking for help.
</font>

<hr width="80%">


<form method="post" action="save.php">


<table width="500" cellpadding="0" cellspacing="5" border="0">
<tr>
	<td align="right" valign="top">
		Path of This File:<br />
	</td>
	<td valign="middle">
		<input type="text" size="20" name="hosturl">
	</td>
</tr>

<tr>
	<td colspan="2" align="center">
		<font size ="2pt">
			(ex. http://www.random.com/movieinfo/moviedata.php<br />
			the path is http://www.random.com/movieinfo/)
		</font>
	</td>
</tr>
</table>

Movies

<hr width="80%">



<table width="500" cellpadding="0" cellspacing="5" border="0">
<caption>Movie #1</caption>
<tr>
	<td align="right" valign="top">
		Movie Name:
	</td>
	<td>
		<input type="text" size="25" maxlength="100" name="mtitle1">
	</td>
</tr>

<tr>
	<td align="right" valign="top">
		Movie Poster URL:
	</td>
	<td>
		<input type="text" size="25" name="mimgurl1">
	</td>
</tr>

<tr>
	<td align="right" valign="top">
		Movie Rating (stars):
	</td>
	<td>
		1:<input type="radio" value="1" name="mrate1"> 2:<input type="radio" value="2" name="mrate1"> 

3:<input type="radio" value="3" name="mrate1"> 4:<input type="radio" value="4" name="mrate1"> 5:<input type="radio" 

value="5" name="mrate1">
	</td>
</tr>

<tr>
	<td align="right" valign="top">
		Movie Review:
	</td>
	<td>
		<textarea rows="5" cols="20" name="mreview1" wrap="soft" wrap="soft" maxlength="125" 

onkeyup="return ismaxlength(this)">(125 Character Limit)</textarea>
	</td>
</tr>
</table>





<hr width="10%">





<table width="500" cellpadding="0" cellspacing="5" border="0">
<caption>Movie #2</caption>
<tr>
	<td align="right" valign="top">
		Movie Name:
	</td>
	<td>
		<input type="text" size="25" maxlength="100" name="mtitle2">
	</td>
</tr>

<tr>
	<td align="right" valign="top">
		Movie Poster URL:
	</td>
	<td>
		<input type="text" size="25" name="mimgurl2">
	</td>
</tr>

<tr>
	<td align="right" valign="top">
		Movie Rating (stars):
	</td>
	<td>
		1:<input type="radio" value="1" name="mrate2"> 2:<input type="radio" value="2" name="mrate2"> 

3:<input type="radio" value="3" name="mrate2"> 4:<input type="radio" value="4" name="mrate2"> 5:<input type="radio" 

value="5" name="mrate2">
	</td>
</tr>

<tr>
	<td align="right" valign="top">
		Movie Review:
	</td>
	<td>
		<textarea rows="5" cols="20" name="mreview2" wrap="soft" wrap="soft" maxlength="125" 

onkeyup="return ismaxlength(this)">(125 Character Limit)</textarea>
	</td>
</tr>
</table>





<hr width="10%">





<table width="500" cellpadding="0" cellspacing="5" border="0">
<caption>Movie #3</caption>
<tr>
	<td align="right" valign="top">
		Movie Name:
	</td>
	<td>
		<input type="text" size="25" maxlength="100" name="mtitle3">
	</td>
</tr>

<tr>
	<td align="right" valign="top">
		Movie Poster URL:
	</td>
	<td>
		<input type="text" size="25" name="mimgurl3">
	</td>
</tr>

<tr>
	<td align="right" valign="top">
		Movie Rating (stars):
	</td>
	<td>
		1:<input type="radio" value="1" name="mrate3"> 2:<input type="radio" value="2" name="mrate3"> 

3:<input type="radio" value="3" name="mrate3"> 4:<input type="radio" value="4" name="mrate3"> 5:<input type="radio" 

value="5" name="mrate3">
	</td>
</tr>

<tr>
	<td align="right" valign="top">
		Movie Review:
	</td>
	<td>
		<textarea rows="5" cols="20" name="mreview3" wrap="soft" wrap="soft" maxlength="125" 

onkeyup="return ismaxlength(this)">(125 Character Limit)</textarea>
	</td>
</tr>
</table>





<hr width="10%">





<table width="500" cellpadding="0" cellspacing="5" border="0">
<caption>Movie #4</caption>
<tr>
	<td align="right" valign="top">
		Movie Name:
	</td>
	<td>
		<input type="text" size="25" maxlength="100" name="mtitle4">
	</td>
</tr>

<tr>
	<td align="right" valign="top">
		Movie Poster URL:
	</td>
	<td>
		<input type="text" size="25" name="mimgurl4">
	</td>
</tr>

<tr>
	<td align="right" valign="top">
		Movie Rating (stars):
	</td>
	<td>
		1:<input type="radio" value="1" name="mrate4"> 2:<input type="radio" value="2" name="mrate4"> 

3:<input type="radio" value="3" name="mrate4"> 4:<input type="radio" value="4" name="mrate4"> 5:<input type="radio" 

value="5" name="mrate4">
	</td>
</tr>

<tr>
	<td align="right" valign="top">
		Movie Review:
	</td>
	<td>
		<textarea rows="5" cols="20" name="mreview4" wrap="soft" wrap="soft" maxlength="125" 

onkeyup="return ismaxlength(this)">(125 Character Limit)</textarea>
	</td>
</tr>
</table>





<hr width="10%">





<table width="500" cellpadding="0" cellspacing="5" border="0">
<caption>Movie #5</caption>
<tr>
	<td align="right" valign="top">
		Movie Name:
	</td>
	<td>
		<input type="text" size="25" maxlength="100" name="mtitle5">
	</td>
</tr>

<tr>
	<td align="right" valign="top">
		Movie Poster URL:
	</td>
	<td>
		<input type="text" size="25" name="mimgurl5">
	</td>
</tr>

<tr>
	<td align="right" valign="top">
		Movie Rating (stars):
	</td>
	<td>
		1:<input type="radio" value="1" name="mrate5"> 2:<input type="radio" value="2" name="mrate5"> 

3:<input type="radio" value="3" name="mrate5"> 4:<input type="radio" value="4" name="mrate5"> 5:<input type="radio" 

value="5" name="mrate5">
	</td>
</tr>

<tr>
	<td align="right" valign="top">
		Movie Review:
	</td>
	<td>
		<textarea rows="5" cols="20" name="mreview5" wrap="soft" wrap="soft" maxlength="125" 

onkeyup="return ismaxlength(this)">(125 Character Limit)</textarea>
	</td>
</tr>
</table>





<hr width="10%">





<table width="500" cellpadding="0" cellspacing="5" border="0">
<caption>Movie #6</caption>
<tr>
	<td align="right" valign="top">
		Movie Name:
	</td>
	<td>
		<input type="text" size="25" maxlength="100" name="mtitle6">
	</td>
</tr>

<tr>
	<td align="right" valign="top">
		Movie Poster URL:
	</td>
	<td>
		<input type="text" size="25" name="mimgurl6">
	</td>
</tr>

<tr>
	<td align="right" valign="top">
		Movie Rating (stars):
	</td>
	<td>
		1:<input type="radio" value="1" name="mrate6"> 2:<input type="radio" value="2" name="mrate6"> 

3:<input type="radio" value="3" name="mrate6"> 4:<input type="radio" value="4" name="mrate6"> 5:<input type="radio" 

value="5" name="mrate6">
	</td>
</tr>

<tr>
	<td align="right" valign="top">
		Movie Review:
	</td>
	<td>
		<textarea rows="5" cols="20" name="mreview6" wrap="soft" wrap="soft" maxlength="125" 

onkeyup="return ismaxlength(this)">(125 Character Limit)</textarea>
	</td>
</tr>
</table>





<hr width="10%">





<table width="500" cellpadding="0" cellspacing="5" border="0">
<caption>Movie #7</caption>
<tr>
	<td align="right" valign="top">
		Movie Name:
	</td>
	<td>
		<input type="text" size="25" maxlength="100" name="mtitle7">
	</td>
</tr>

<tr>
	<td align="right" valign="top">
		Movie Poster URL:
	</td>
	<td>
		<input type="text" size="25" name="mimgurl7">
	</td>
</tr>

<tr>
	<td align="right" valign="top">
		Movie Rating (stars):
	</td>
	<td>
		1:<input type="radio" value="1" name="mrate7"> 2:<input type="radio" value="2" name="mrate7"> 

3:<input type="radio" value="3" name="mrate7"> 4:<input type="radio" value="4" name="mrate7"> 5:<input type="radio" 

value="5" name="mrate7">
	</td>
</tr>

<tr>
	<td align="right" valign="top">
		Movie Review:
	</td>
	<td>
		<textarea rows="5" cols="20" name="mreview7" wrap="soft" wrap="soft" maxlength="125" 

onkeyup="return ismaxlength(this)">(125 Character Limit)</textarea>
	</td>
</tr>
</table>






<input type="submit" value="save" name="save">
</form>


</center>

</font>

</body>
</html>

 

I'm hoping to keep the same setup as far is accessing "save.php" to save the file to text. So if someone could give me an example of how to save multiple variables that would be awesome.

 

Thank You for taking time to read!

Link to comment
Share on other sites

well, I've followed the tizag.com and about.com tuts but I'm still having the same problem. I'm not getting enough specific information for what I'm trying to do and both times, the text file that has been written remains blank.

 

I have all the form names and then form action set to save.php. On which page do I need to define all of the strings? one of the tuts I read on tizag said to put it on the main (in this case moviedata.php) page but in all the other tutorials I've read so far, the strings are defined in what I want to be the save file.

 

Either way, everything comes back blank.

 

With what I've posted in the code section in my first post, can someone just show me what would need to be in the save.php to make it function correctly? Not like the entire file but maybe just how to record the first two variables or something?

 

I'm so new to this stuff that I don't know what questions to ask an I don't know if maybe my server is acting up or what.

Link to comment
Share on other sites

with Ilya's code it should be something like:

 

<?php
$hosturl = $_POST["hosturl"];
$mtitle1 = $_POST["mtitle1"];

$content=$hosturl . "," . $mtitle1 . "\n";
$filename="yourfile.txt";
$fin=fopen($filename,"w");
fwrite($fin,$content);
fclose($fin);
?>

 

if you're still having problems with this then you don't have proper permissions to write to that file.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.