Hi, i've been asked to create a visit counter using checkboxes and a submit button. When a form (available form - code below) is submitted (pressed visit button) a script should work out which properties have been selected (using checkboxes) by the user and then add one to the Visits field of the selected property. I have created a text file where it will update and record the visit field of a property once it has been selected by the user.

code for available.form

<html>
<body>
<h3> Select the Property Price </h3>
<FORM ACTION="available.php" METHOD="POST">

</select>

Enter maximum price: <input type= "text" name= "maxprice" placeholder="Enter Amount" size="15"> <br>
<input type ="submit"> 

</form>
</body>
</html>

<html>
<body>
<FORM ACTION="available.php" METHOD="POST">

<?php

$searchPrice = $_POST['maxprice'];

$filename = "propertieslist.txt";
 $filepointer = fopen($filename,"r");  // open for read
 $myarray = file ($filename);

 for ($mycount = 0; $mycount < count($myarray); $mycount++ )

    {   
        // one input line at a time
        $aline = $myarray[$mycount];    
        $postcode = &getvalue ($aline, 0);
    $price  =  &getvalue($aline,1);
    $house = &getvalue ($aline, 2);
    $visit  =  &getvalue($aline,3);     


    if($searchPrice >= $price)

    {
    ?><br><br> <input type = "checkbox" name = "aline"> <?
     print "$postcode <br>";
     print "$price <br>";
     print "$house <br>";
     print "$visit <br><br>";  
    }


 fclose ($filepointer);
function getvalue ($text, $commaToLookFor)
{   
 $intoarray = explode(",",$text);
 return  $intoarray[ $commaToLookFor];  
}

 if (!($filepointer = fopen($filename,"r")))  { exit; }


?>
<input type= "button" name= "visit"  value= "Visit"> <br>
</form>
</body>
</html>

Thats my code so far and im stuck on how to create the code when the user press the submit button. Thanks so much for the help!

i guess you want a counter for every time the visitor click's a button?
do you use a database?

Nope im not using a db. Its basically a simple form that when the user enters a maximum price all the properties inside the text will come up with a checkbox next to it allowing the user to select a property to visit by pressing the submit button.

Can i have ur email po if u dont mind? Im filipino too. I really need help po talaga

i just have a search button but dunno wat your really looking for.
try this

if(isset($_POST['submit'])){
$search = $_POST['maxprice'];
$lines = file('propertieslist.txt');
// Store true when the text is found
$found = false;
foreach($lines as $line)
{
  if(strpos($line, $search) !== false)
  {
    $found = true;
    echo "<input type='checkbox'>".$line."<br>";
  }
}
// If the text was not found, show a message
if(!$found)
{
  echo 'No match found';
}
}

Thanks for that! This is the complete spec.

Use a text editor to make a comma delimited text file containing data of properties for sale with the following
fields/columns: Postcode, Price(thousands), imagefilename, Visits
(Eg: HA13TP, 250,house1.jpg, 3)

  1. Display all property information. The screen display can be any simple and sensible layout. Call the script
    plist.php.

  2. Display all property details below a maximum price (the user enters the price in a field on a static web form - the
    price is read in by the script and used to find the property details as the script reads through the property text file)
    Call the script maximum.php

  3. Allow the user to enter a search term - and the web page will display the full details of all the properties
    containing the user’s search term included in part of any field value. Call the script psearch.php

  4. Display on the screen all details of properties which are below a maximum price entered by the user, and allow a
    user the option of selecting any of the properties shown (read the property file and for each property shown display
    the property details in a form with a checkbox next to the property details ). ( available.php )

  5. The user intends to visit properties they have selected in part 4. When the form for part 4 is submitted a script
    should work out which properties have been selected by the user and then add one to the Visits field of the selected
    property. You must fully understand any code you use. ( visit.php )

I've done part 1-4 but im struggling with 5.

<?php
$searchPrice = $_POST['maxprice'];

$filename = "propertieslist.txt";
$filepointer = fopen($filename,"r");  // open for read
$myarray = file ($filename);

for ($mycount = 0; $mycount < count($myarray); $mycount++ )
{   
    // one input line at a time
    $aline = $myarray[$mycount];    
    $postcode = &getvalue ($aline, 0);
    $price  =  &getvalue($aline,1);
    $house = &getvalue ($aline, 2);
    $visit  =  &getvalue($aline,3);     

    if($searchPrice >= $price)
    {
    ?><br><br> <input type = "checkbox" name = "aline[]" value= "yes"> <?
     print "$postcode <br>";
     print "$price <br>";
     print "$house <br>";
     print "$visit <br><br>";  
    }
}

fclose ($filepointer);

function getvalue ($text, $commaToLookFor)
{   
  $intoarray = explode(",",$text);
  return  $intoarray[ $commaToLookFor];  
}
?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.