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
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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.