Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Nov 2007
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    HOW DO i MAKE A NUMBER IN MY TEXT FILE TO DISSAPEAR OR OVERWRITE IT USING PHP?

    sorry i am new to this, but still learning:

    if someone want to book a seat for a property course, they have to enter a seat no into a html form, but i am looking for a solution using PHP or JAVASCRIPT so that once they enter a seat no and a name, the array will then display a x to state that that seat has ben booked already, is there a way round this?? can i overwrite it?


    this is my text file:
    |1 |11|21|31|41|51|71|81
    |2 |12|22|32|42|52|72|82
    |3 |13|23|33|43|53|73|83
    |4 |14|24|34|44|54|74|84
    |5 |15|25|35|45|55|75|85
    |6 |16|26|36|46|56|76|86
    |7 |17|27|37|47|57|77|87
    |8 |18|28|38|48|58|78|88
    |9 |19|29|39|49|59|79|89
    |10|20|30|40|50|60|80|90

    his is the PHP using to read the text file.

    <center>
    <table summary="List of demo fields">
    <tr>
    <th>Row 1</th>
    <th>Row 2</th>
    <th>Row 3</th>
    <th>Row 4</th>
    <th>Row 5</th>
    <th>Row 6</th>
    <th>Row 7</th>
    <th>Row 8</th>
    </tr>

    <?php
    $file = fopen('seats.txt','r');
    if (!$file) {echo 'ERROR: Unable to open file.</table></body></html>'; exit;}

    while (!feof($file)) {
    $line = fgets($file);
    list ($field1, $field2, $field3, $field4, $field5, $field6, $field7, $field8) = split ('\|', $line);
    echo '
    <tr>
    <td>'.$field1.'</td>
    <td>'.$field2.'</td>
    <td>'.$field3.'</td>
    <td>'.$field4.'</td>
    <td>'.$field5.'</td>
    <td>'.$field6.'</td>
    <td>'.$field7.'</td>
    <td>'.$field8.'</td>
    </tr>';
    $file++;
    }

    fclose($file);

    echo '
    </table>

    <p><small>12 October 2004 &middot; Last updated: '.date('j F Y', getlastmod()); ?>

    <br/>
    <br/>
    <center>
    <h2> Please enter your Name, Seat No & Phone Number</h2>
    <form action="upload.php" method="get">

    First Name: <input type="text" name="CustFname" size="20" /><br/><br/>
    last Name: <input type="text" name="CustLname" size="20" /><br/><br/>
    Mobile No: <input type="text" name="MobileNo" size="20" /><br/><br/>
    Seat No: <input type="text" name="SeatNo" size="20" /><br/><br/>
    <input type="submit" value="Submit" name="Submit" /><br/><br/>
    </form>
    </center>

  • #2
    Senior Coder
    Join Date
    Jan 2007
    Posts
    1,648
    Thanks
    1
    Thanked 58 Times in 54 Posts
    Sorry, I can't reply right now. My ears are ringing.

  • #3
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,039
    Thanks
    2
    Thanked 316 Times in 308 Posts
    Triple-cross post and there were already two threads open concerning the same piece of code.

    titch35, start one thread at a time for the same problem.

    Cross posting, repeatedly posting the same problem, and posting anything in all CAPITAL letters will just earn you infractions and possibly get you banned. Also, doing those things will tend to get your post's ignored and left unanswered.

    Show consideration and patience toward the Forum and the Forum will show consideration and patience back.
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #4
    Regular Coder
    Join Date
    Nov 2007
    Location
    Leeds, UK
    Posts
    514
    Thanks
    24
    Thanked 19 Times in 19 Posts
    Sorry Night readin dont woke lol
    this is my text file:
    |1 |11|21|31|41|51|71|81
    |2 |12|22|32|42|52|72|82
    |3 |13|23|33|43|53|73|83
    |4 |14|24|34|44|54|74|84
    |5 |15|25|35|45|55|75|85
    |6 |16|26|36|46|56|76|86
    |7 |17|27|37|47|57|77|87
    |8 |18|28|38|48|58|78|88
    |9 |19|29|39|49|59|79|89
    |10|20|30|40|50|60|80|90

    his is the PHP using to read the text file.

    <center>
    <table summary="List of demo fields">
    <tr>
    <th>Row 1</th>
    <th>Row 2</th>
    <th>Row 3</th>
    <th>Row 4</th>
    <th>Row 5</th>
    <th>Row 6</th>
    <th>Row 7</th>
    <th>Row 8</th>
    </tr>

    <?php
    $file = fopen('seats.txt','r');
    if (!$file) {echo 'ERROR: Unable to open file.</table></body></html>'; exit;}

    while (!feof($file)) {
    $line = fgets($file);
    list ($field1, $field2, $field3, $field4, $field5, $field6, $field7, $field8) = split ('\|', $line);
    echo '
    <tr>
    <td>'.$field1.'</td>
    <td>'.$field2.'</td>
    <td>'.$field3.'</td>
    <td>'.$field4.'</td>
    <td>'.$field5.'</td>
    <td>'.$field6.'</td>
    <td>'.$field7.'</td>
    <td>'.$field8.'</td>
    </tr>'; //First echo edded
    $file++; // why do you want to add one to file ???
    }

    fclose($file); // closes file

    echo ' //echo starting - Use HTML Get rid of this Echo and end PHP it quicker
    </table>

    <p><small>12 October 2004 &middot; Last updated: '.date('j F Y', getlastmod()); ?>

    <br/>
    <br/>
    <center>
    <h2> Please enter your Name, Seat No & Phone Number</h2>
    <form action="upload.php" method="get">

    First Name: <input type="text" name="CustFname" size="20" /><br/><br/>
    last Name: <input type="text" name="CustLname" size="20" /><br/><br/>
    Mobile No: <input type="text" name="MobileNo" size="20" /><br/><br/>
    Seat No: <input type="text" name="SeatNo" size="20" /><br/><br/>
    <input type="submit" value="Submit" name="Submit" /><br/><br/>
    </form>
    </center>
    ';// OR You need to end you echo
    Chedck your Quote i have noted it for you
    Last edited by barkermn01; 11-16-2007 at 12:20 PM.

  • #5
    New to the CF scene
    Join Date
    Nov 2007
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    This is what i have put together using this code, but is coming up with an error on line 19? cant see the problem tho, any help would be great.

    This is the text file:

    |1 |11|21|31|41|51|71|81
    |2 |12|22|32|42|52|72|82
    |3 |13|23|33|43|53|73|83
    |4 |14|24|34|44|54|74|84
    |5 |15|25|35|45|55|75|85
    |6 |16|26|36|46|56|76|86
    |7 |17|27|37|47|57|77|87
    |8 |18|28|38|48|58|78|88
    |9 |19|29|39|49|59|79|89
    |10|20|30|40|50|60|80|90

    and what i am trying to do is to provide a html form and ask the customer to choose a seat no, then it should delete it from the text file, but it aint working

    this is the code i have put together to try and solve it.


    <form action="delete.php" method="post">
    name: <input type="text" name="seatno" size="20" />
    <input type="submit" />
    </form>

    <?php
    //open file
    $fp = fopen('seats.txt', 'r');

    //declare array and counter
    $lines = array();
    $i = 0;

    //each line goes to new item in array
    while(!feof($fp)) {
    $lines[$i] = fgets($fp);
    $i++;
    }

    //close file
    fclose($fp);

    //remove seatno
    for($i = 0; i < count($lines); i++) {
    //if current line matches seat to be removed
    if($lines[i] == $_POST['seatno']) {
    //splice from array and exit for loop
    array_splice($lines, $i + 1, 1);
    break;
    }
    }

    //open output file for writing
    $fp = fopen('seats.txt', 'w');
    //output to file
    foreach($lines as $line) {
    fwrite("$line\n");
    }
    fclose($fp);

    echo "you have chosen seat no" . $_POST[seatno] ";
    ?>


    thank you


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •