...

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



titch35
11-15-2007, 06:20 PM
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>

aedrin
11-15-2007, 06:22 PM
Sorry, I can't reply right now. My ears are ringing.

CFMaBiSmAd
11-15-2007, 06:40 PM
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.

barkermn01
11-15-2007, 11:31 PM
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

titch35
11-16-2007, 01:18 PM
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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum