Hey
i have this code that should update database on submit of a form.
i have multiple rows selected from a database and i need to be able to update each row individually...however currently as the code stands it updates all rows with the data entered into the bottom row.
i dont know how to solve this its very frustrating
could someone take a look and help me?
here is the code
<?php
session_start();
?>
<a href="adminlogout.php">Logout</a><br />
<?php
$id = $_GET['id'];
if(!isset($_SESSION['myusername'])) {
header("location:adminlogin.php");
}
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = '';
$db = 'bank';
$conn = mysql_connect($dbhost,$dbuser,$dbpass);
mysql_select_db($db);
if(isset($_POST['submit'])){
$select = mysql_query("SELECT * FROM accounts WHERE cusid=$id");
$row3 = mysql_fetch_array($select);
$update = mysql_query("UPDATE accounts SET balance='".$_POST['balance']."', type='".$_POST['type']."', name='".$_POST['name']."', active='".$_POST['active']."' WHERE cusid=$id");
}
$result = mysql_query("SELECT * FROM customer WHERE cusid=$id");
$row2 = mysql_fetch_array($result);
echo $row2['name'] . "'s bank accounts" . "<br><br>";
$result2 = mysql_query("SELECT * FROM accounts WHERE cusid=$id");
echo "<form method='post' action='accounts.php?id=$id'>";
while($row = mysql_fetch_array($result2))
{
echo "<input type='text' name='accno' style='background-color:lightgrey;' readonly='readonly' value='$row[accno]'>" . "<input type='text' name='name' value='$row[name]'>"; if($row['type'] == "Current"){echo"<select name='type'>" . "<option selected='Selected'>Current</option>" . "<option>Savings</option>" . "</select>";} else{echo"<select name='type'>" . "<option selected='Selected'>Savings</option>" . "<option>Current</option>" . "</select>";} echo"<input type='text' name='balance' value='$row[balance]'>"; if($row['active'] == "No"){ echo "<select name='active'>" . "<option value='No' selected='selected'>No</option>" . "<option value='Yes'>Yes</option>" . "</select>";} elseif($row['active'] == "Yes"){echo "<select name='active'>" . "<option value='Yes' selected='selected'>Yes</option>" . "<option value='No'>No</option>" . "</select>";} echo "<input type='submit' name='submit' value='Update'>" . "<br>";
}
echo "</form>";
?>