Jump to content

HELP updating database please please!!


busby

Recommended Posts

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>";
?>

Link to comment
https://forums.phpfreaks.com/topic/223355-help-updating-database-please-please/
Share on other sites

all that code is accounts.php

 

it selects the data from database and displays it in rows on the page. each bit of data is displayed in a text box for the user to edit...and then there is a submit button at the end of each row which when clicked should update that particular row in the database with the new edited info.

 

but at the moment when the submit button is clicked it just updates all the rows with whatever the bottom row says.

it shouldnt be updating multiple rows. there is a submit button at the end of each row...the user will edit the data in the text boxes of a row...then press the submit button at the end of that row and it should update that row in the database.

 

no other rows should get updated

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.