Jump to content

update of multiple records not working


busnut

Recommended Posts

G'day again. Since my last post, I have attempted to try and make a multiple edit script, whereby instead of editing each record individually, I can search for a particular range (like bus or make of bus) so I can edit more than one record at once to save time, however I have struck two problems. The main being that the script is not updating the information, and secondly that when searching for say a bus make where there could be several hundred records, the page is really slow to display.

 

here is the script if anyone can see why she isn't working :(

 

<h1>Bus Fleet Update Facility</h1>

 

<form name="search" method="post" action="update1.php">

Seach for: <input type="text" name="find" /> in

<Select NAME="field">

<Option VALUE="busno">Bus</option>

<Option VALUE="chassisbody">Chassis [body]</option>

<Option VALUE="depot">Depot</option>

<Option VALUE="active">Status</option>

</Select>

<input type="hidden" name="searching" value="yes" />

<input type="submit" name="search" value="Search" />

</form>

 

<?php

//This is only displayed if they have submitted the form

if ($searching =="yes")

{

 

//If they did not enter a search term we give them an error

if ($find == "")

{

echo "<p>You forgot to enter a search term";

exit;

}

 

$host="localhost"; // Host name

$username="btbuses_admin"; // Mysql username

$password="PJNROTTO24378"; // Mysql password

$db_name="btbuses_businformation"; // Database name

$tbl_name="busfleet"; // Table name

 

// Connect to server and select databse.

mysql_connect("$host", "$username", "$password")or die("cannot connect");

mysql_select_db("$db_name")or die("cannot select DB");

 

// We preform a bit of filtering

$find = strtoupper($find);

$find = strip_tags($find);

$find = trim ($find);

 

$sql="SELECT * FROM busfleet WHERE upper($field) LIKE'%$find%' ORDER BY busno ASC";

$result=mysql_query($sql);

 

// Count table rows

$count=mysql_num_rows($result);

?>

<form name="FormName" method="post" action="update1.php" id="FormName">

 

<table width="500" border="0" cellspacing="1" cellpadding="0">

<tr>

<td align="center"><strong>ID</strong></td>

<td align="center"><strong>Bus</strong></td>

<td align="center"><strong>Chassis [body]</strong></td>

<td align="center"><strong>VIN</strong></td>

<td align="center"><strong>Body No</strong></td>

<td align="center"><strong>Delivered</strong></td>

<td align="center"><strong>Withdrawn</strong></td>

<td align="center"><strong>Depot</strong></td>

<td align="center"><strong>Rego</strong></td>

<td align="center"><strong>Active</strong></td>

<td align="center"><strong>AC</strong></td>

<td align="center"><strong>WC</strong></td>

<td align="center"><strong>Fuel</strong></td>

<td align="center"><strong>Advertising</strong></td>

<td align="center"><strong>History</strong></td>

<td align="center"><strong>Notes</strong></td>

</tr>

 

<?php

while($rows=mysql_fetch_array($result)){

?>

 

<tr>

<td align="center"><? $id[]=$rows['id']; ?><? echo $rows['id']; ?></td>

<td align="center"><input name="busno[]" type="text" id="busno" value="<? echo $rows['busno']; ?>" size=5></td>

<td align="center"><input name="chassisbody[]" type="text" id="chassisbody" value="<? echo $rows['chassisbody']; ?>" size=25></td>

<td align="center"><input name="vin[]" type="text" id="vin" value="<? echo $rows['vin']; ?>"></td>

<td align="center"><input name="bodyno[]" type="text" id="bodyno" value="<? echo $rows['bodyno']; ?>"></td>

<td align="center"><input name="delivered[]" type="text" id="delivered" value="<? echo $rows['delivered']; ?>" size=10></td>

<td align="center"><input name="withdrawn[]" type="text" id="withdrawn" value="<? echo $rows['withdrawn']; ?>" size=10></td>

<td align="center"><input name="depot[]" type="text" id="depot" value="<? echo $rows['depot']; ?>"></td>

<td align="center"><input name="rego[]" type="text" id="rego" value="<? echo $rows['rego']; ?>" size=7></td>

<td align="center"><input name="active[]" type="text" id="active" value="<? echo $rows['active']; ?>" size=2></td>

<td align="center"><input name="ac[]" type="text" id="ac" value="<? echo $rows['ac']; ?>" size=2></td>

<td align="center"><input name="wc[]" type="text" id="wc" value="<? echo $rows['wc']; ?>" size=2></td>

<td align="center"><input name="fuel[]" type="text" id="fuel" value="<? echo $rows['fuel']; ?>" size=10></td>

<td align="center"><input name="livery[]" type="text" id="livery" value="<? echo $rows['livery']; ?>"></td>

<td align="center"><input name="history[]" type="text" id="history" value="<? echo $rows['history']; ?>"></td>

<td align="center"><input name="notes[]" type="text" id="notes" value="<? echo $rows['notes']; ?>"></td>

</tr>

 

<?php

}

?>

 

<tr>

<td colspan=16><input type="submit" name="Submit" value="Submit"></td>

</tr>

</table>

 

</form>

 

<?php

// Check if button name "Submit" is active, do this

if($Submit){

for($i=0;$i<$count;$i++){

 

if ($active1=="N" && $active=="Y") $history1 = "\n". date(M) ." " . date(Y) .": Delivered to $depot\n";

if ($active1=="Y" && $active=="N") { $history1 = date(M) ." " . date(Y) .": Withdrawn from $depot\n"; $depot="Withdrawn"; }

if ($active1=="Y" && $active=="Y" && $depot1 <> $depot) $history1 = date(M) ." " . date(Y) .": Transferred from $depot1 to $depot\n";

if ($active1=="Y" && $rego1 <> $rego) $history3 = date(M) ." " . date(Y) .": Rego changed from $rego1 to $rego\n";

if ($active1=="Y" && strlen($livery1)>2 && $livery=="") $history4 = date(M) ." " . date(Y) .": AOA removed\n";

if ($active1=="Y" && $livery1<>$livery && $livery<>"") $history4 = date(M) ." " . date(Y) .": AOA for $livery\n";

if ($active1=="Y" && $ac1=="N" && $ac=="Y") $history5 = date(M) ." " . date(Y) .": Air-Conditioning Installed\n";

if ($active1=="Y" && $ac1=="Y" && $ac=="N") $history5 = date(M) ." " . date(Y) .": Air-Conditioning Removed\n";

if ($notes<>"") $noted = date(M) ." ". date(Y) .": $notes\n";

 

$history = $history1 ."". $history2 ."". $history3 ."". $history4 ."". $history5 . "" . $noted;

 

$sql1="UPDATE busfleet SET busno='$busno[$i]', chassisbody='$chassisbody[$i]', vin='$vin[$i]', bodyno='$bodyno[$i]', delivered='$delivered[$i]', withdrawn='$withdrawn[$i]', depot='$depot[$i]', rego='$rego[$i]', active='$active[$i]', ac='$ac[$i]', wc='$wc[$i]', fuel='$fuel[$i]', livery='$livery[$i]', history = CONCAT(history,'$history[$i]') WHERE id='$id[$i]'";

$result1=mysql_query($sql1);

}

}

 

if($result1){

echo "update successful";

}

 

mysql_close();

}

?>

 

Prior to adding the search, she worked although slowed the system exceptionally down and had to scroll down some 2000 records to find the one I want to edit, but since adding the search, she displays my searched results, but won't edit :(. So what have I left out? Any help is appreciated.

Link to comment
https://forums.phpfreaks.com/topic/145854-update-of-multiple-records-not-working/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.