| |||||||
| Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics. |
![]() |
| | LinkBack | Thread Tools |
| | #1 (permalink) |
| RyanPrice.ca - Developer | Quick PHP question - fopen() and related Ok, I have a form set up with the code listed below. What I'm trying to do is when the user submits the form the following happens: 1) The file with the data is opened. This will contain 2 numbers. One holding the number of votes and one with the vote total (explained in more detail later). 2) the two numbers are stored to two variables, $voteTotal and $numVotes or something like that. 3) The new vote is added to $voteTotal (its a rating script so this will be a number between 1 and 10) and $numVotes is increased by one. 4) Finally, I want to the file saved and closed. The data still stored in $numVotes and $voteTotal will be used to display an avg rating (avg = $voteTotal/$numVotes). As you can see I have this planned out I just can't compeltely figure out how the fopen() fread() and fwrite() functions work. Any help would be appreciated. Here is the code for the form: PHP Code:
__________________ Ryan Price - Webmaster www.HostDurham.com - For Hosting | www.jeanco.ca - For Webdesign |
| |
| | #2 (permalink) |
| Senior Member | are the votes stored in one text file? http://uk.php.net/manual/en/function.fwrite.php this page should explain most of what you need fopen will load a file so it can be read. written etc etc fopen("local/path/to/file", "r+"); the r+ tells php that you need to write to the file fread will open the contents of the file you just opened fwrite will write to the file fclose is needed to free up the resources of the opened file if not php.net/fread php.net/fopen Last edited by adam_uk; 06-01-2004 at 03:22 PM. |
| |
| | #3 (permalink) |
| NamePros Founder Administrator | Hi Ryan, Can you post the snippet from process.php where you read the values and write using fopen? You may want to consider writing the data to a simple two column MySQL table. It's more reliable than text files and easier to manage. Also the form you posted seems somewhat unusual. Will that work? This kind of format is what I would use Code: <form action="process.php" method="get">
<select name="rating" onChange="MM_jumpMenu('parent',this,0)">
<option>Rate It!</option>
<option>----------</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
</select>
</form>
|
| |
| | #4 (permalink) |
| RyanPrice.ca - Developer | Here is the code I'm using at the moment. I know its not completely efficient (recommend changes if you see them, I'm sitll learning). Its having a bit of problems outputting the results (I'm getting a header error), but its a start: PHP Code:
__________________ Ryan Price - Webmaster www.HostDurham.com - For Hosting | www.jeanco.ca - For Webdesign |
| |
| | #5 (permalink) | |
| NamePros Member | PHP Code: You have to phase out you url. Quote:
PHP Code:
__________________ Click Link for Java IRC PHP-Live IRC: pgardner.net:6667, Channel: #php. Last edited by Pablo; 06-07-2004 at 08:40 AM. | |
| |
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| |