c0deM0nK424
Programmer
basicly i have a form where the user enters a price in the form of 5.99, clicks the submit button and then a php script ive written opens up a text file, a comma delimitted text file in the form of:
shadow dancer,amiga 500,1991,3.99,25,
final fight,amiga 500/500+,1991,4.59,40,
rodland,amiga 500,1992,1.50,65,
the adams family,amiga 500+,1993,2.59,55,
arabian nights, amiga 500+,1994,5.99,43,
batman:the movie,amiga 500,1989,3.99,60,
apidya,amiga 500+,1994,3.69,55,
the file holds classic computer games for the old commodore amiga 500/500+ platform. the 5 fields hold information on the game title, the amiga machine it runs on, the year of release, the price and the last field holds how many of those games are in stock.
now, when the user enters a price, say 4.59 - my script displays all the games that are below that price - onto the browser appended with a checkbox next to it. so basicly only those games that are under 4.59 are shown line by line with a checkbox next to it.
my script does that fine, but its the next bit im trying hard to figure out. what i want it to do from here is allow the user the option to select some or all of those games listed (that fell below the price user entered in the form). the user checks two boxes, which correspond to that game and then hits a submit button.
in the background , upon the user hitting the submit button, i need to somehow retrieve the checkbox that was checked alongside its value (which ive assigned as a variable , that holds a line of text read in from the text file) and using each of these pieces of data, go back to the games.txt file and ammend the last field, the stock level. i know there is going to be reading/writing back to the text file but its just GETTING the details of games chosen back out so i can do the reading/writing and changing of stock for that game.
when you see my scripts, you'll see why i cant use name='something[]' value="" , as ive tried to assign the counter variables value to the value of the checkboxes themselves, i.e $boxname = $count.
are you with me on this ?
its extremely hard to figure out how to do this, i heard you can pass the checkbox name and values as hidden fields - how one retrieves hidden fields is beyond me. some tips or advice would be welcomed, just to point me in teh right direction.
i will paste my scripts/code on here now.
============================================================
<html><head><title> checkbox fields </title> </head> </body>
<FORM METHOD="POST" ACTION="bought2.php">
<?
$price = $_POST['price'];
$filename = "games.txt";
$filepointer = fopen($filename,"r");
$myarray = file($filename);
for ($mycount=0; $mycount < count($myarray);$mycount++)
{
$aline = $myarray[$mycount];
$HF = $aline;
$boxname = $mycount;
pricefind($aline,$price,$boxname,$HF);
}
function pricefind($a,$p,$bn,$HF)
{
$fields = explode(",",$a);
if ($fields[3] < $p)
{
$game = implode(",",$fields);
print "$game <INPUT TYPE='checkbox' NAME='$bn' value ='$game'>"."<br>";
print " <input type = 'hidden' name = '$bn' value = '$HF' >";
}
}
?>
<p>
<input type="submit" name="button" value="click to buy Games's">
</form></body></html>
=========================================================
the mytest.htm script is a form with a text field , that is named 'price'.
shadow dancer,amiga 500,1991,3.99,25,
final fight,amiga 500/500+,1991,4.59,40,
rodland,amiga 500,1992,1.50,65,
the adams family,amiga 500+,1993,2.59,55,
arabian nights, amiga 500+,1994,5.99,43,
batman:the movie,amiga 500,1989,3.99,60,
apidya,amiga 500+,1994,3.69,55,
the file holds classic computer games for the old commodore amiga 500/500+ platform. the 5 fields hold information on the game title, the amiga machine it runs on, the year of release, the price and the last field holds how many of those games are in stock.
now, when the user enters a price, say 4.59 - my script displays all the games that are below that price - onto the browser appended with a checkbox next to it. so basicly only those games that are under 4.59 are shown line by line with a checkbox next to it.
my script does that fine, but its the next bit im trying hard to figure out. what i want it to do from here is allow the user the option to select some or all of those games listed (that fell below the price user entered in the form). the user checks two boxes, which correspond to that game and then hits a submit button.
in the background , upon the user hitting the submit button, i need to somehow retrieve the checkbox that was checked alongside its value (which ive assigned as a variable , that holds a line of text read in from the text file) and using each of these pieces of data, go back to the games.txt file and ammend the last field, the stock level. i know there is going to be reading/writing back to the text file but its just GETTING the details of games chosen back out so i can do the reading/writing and changing of stock for that game.
when you see my scripts, you'll see why i cant use name='something[]' value="" , as ive tried to assign the counter variables value to the value of the checkboxes themselves, i.e $boxname = $count.
are you with me on this ?
its extremely hard to figure out how to do this, i heard you can pass the checkbox name and values as hidden fields - how one retrieves hidden fields is beyond me. some tips or advice would be welcomed, just to point me in teh right direction.
i will paste my scripts/code on here now.
============================================================
<html><head><title> checkbox fields </title> </head> </body>
<FORM METHOD="POST" ACTION="bought2.php">
<?
$price = $_POST['price'];
$filename = "games.txt";
$filepointer = fopen($filename,"r");
$myarray = file($filename);
for ($mycount=0; $mycount < count($myarray);$mycount++)
{
$aline = $myarray[$mycount];
$HF = $aline;
$boxname = $mycount;
pricefind($aline,$price,$boxname,$HF);
}
function pricefind($a,$p,$bn,$HF)
{
$fields = explode(",",$a);
if ($fields[3] < $p)
{
$game = implode(",",$fields);
print "$game <INPUT TYPE='checkbox' NAME='$bn' value ='$game'>"."<br>";
print " <input type = 'hidden' name = '$bn' value = '$HF' >";
}
}
?>
<p>
<input type="submit" name="button" value="click to buy Games's">
</form></body></html>
=========================================================
the mytest.htm script is a form with a text field , that is named 'price'.