Hi people,
im having a little trouble with using the query function within php. First off, im trying to make a bank system where the user can send money to another bank account using the bank account
-
so i created a form with checkboxes with variable names so i can call & apply if statements to them.
-
i created a variable called transaction with 2 queries withit, 1 is to update the customer form with a new interger amount that increase the mysql database defualt by whatever the person puts into the textbox,
whilist…
inserting a new record into the transactions record to go along with the update, as not to have blanks within the table, so it will look like a cascading style bank statement.
its session controled also, but however when i click on any of the checkboxe’s and click on the update system it, doesn’t enter it into the system just refreshes the text box.
please help.
php code below
[php]<?php
session_start();
if ($_SESSION[‘username’])
echo “If this isnt’t, “.$_SESSION[‘username’].”
Logout!”;
else
die (“You must be logged in !”);
?>
Direct - Debit
<?php
// CONNECTING TO DATABASE[/img]
$link = mysql_connect ("194.81.104.22", "www", "www");
mysql_select_db ("solAl");
// GET NEW RECORD ENTRY
$Account_number = $_GET['Account_number'];
$username = $_GET['username'];
$Description = $_GET['Description'];
$Card_Used = $_GET['Card_Used'];
$Balance = $_GET['Balance'];
$Amount_Pay_in = $_GET['Amount_Pay_in'];
// GET CHECKBOXES
$add = $_GET['add'];
$modify = $_GET['modify'];
$delete = $_GET['delete'];
$return = $_GET['return'];
// GET EXISTING RECORDS
$Account_numberS = $_GET['Account_numberS'];
$usernameS = $_GET['usernameS'];
$DescriptionS = $_GET['DescriptionS'];
$Card_UsedS = $_GET['Card_UsedS'];
$BalanceS = $_GET['BalanceS'];
if ($add == "add")
{
$query = "INSERT INTO Transaction (Account_number, username, Description, Card_Used, Balance) VALUES ('$Account_number', '$username', '$Description', '$Card_Used', '$Balance');";
$result = mysql_query ($query);
}
// RELOAD UPDATED DATABASE AFTER ANY NEW INSERTED RECORDS
$query = "SELECT * FROM Transaction";
$result = mysql_query ($query);
// MAKE MODIFICATIONS TO DATABASE
for ($i = 0; $i < mysql_num_rows ($result); $i ++)
{
if ($modify [$i] == "modify")
{
$query = "update Transaction SET Account_number='$Account_numberS[$i]', username='$usernameS[$i]', Description='$DescriptionS[$i]', Card_Used='$Card_UsedS[$i]', Balance='$BalanceS[$i]', WHERE Account_number = '$Account_number[$i]'";
$result1 = mysql_query ($query);
}
}
// RELOAD DATABASE AFTER MODIFICATIONS
$query = "SELECT * FROM Transaction";
$result = mysql_query ($query);
// DELETE ANY RECORDS IN DATABASE
for ($i = 0; $i < mysql_num_rows ($result); $i ++)
{
if ($delete [$i] == "delete")
{
$query = "DELETE FROM Transaction WHERE Account_number = '$Account_numberS[$i]'";
$result1 = mysql_query ($query);
}
}
$query = "SELECT * from Transaction";
$result = mysql_query ($query);
for ($i = 0; $i < mysql_num_rows ($result); $i ++)
{
if ($Direct_Debit [$i] == "checkout")
{
$BalanceS[$i] = $BalanceS[$i] + $Amount_Pay_in;
$queryincrease = "UPDATE Banky SET Current_Account = '$Balances[$i]' WHERE username = '.$_SESSION[username]'.";
$result1 = mysql_query ($queryincrease);
$queryInsert = "INSERT INTO Transaction (Account_number, username, Description, Card_Used) VALUES ('$Account_number', '$username', '$Description', '$Card_Used');";
$result2 = mysql_query ($queryInsert);
}
}
//Reload Database after increasing
$query = "SELECT * from Transaction";
$result = mysql_query ($query);
// UPDATE TABLE TO BE DISPLAYED
print ("<form action=\"Direct_Debit.php\" method=\"get\">");
print ("<table border='1'>");
print ("<tr><th>Account_number</th><th>username</th><th>Description</th><th>Card_Used</th><th>Balance</th><th>Amount_Pay_in</th><th colspan='2'> </th></tr>");
print ("<td><input type=\"text\" name=\"Account_number\" size=15></td>");
print ("<td><input type=\"text\" name=\"username\" size=15></td>");
print ("<td><input type=\"text\" name=\"Description\" size=15></td>");
print ("<td><input type=\"text\" name=\"Card_Used\" size=15></td>");
print ("<td><input type=\"text\" name=\"Balance\" size=15></td>");
print ("<td><input type=\"text\" name=\"Amount_Pay_in\" size=15></td>");
print ("<td colspan='2' align='center'>Add<input type=\"checkbox\" name=\"add\" value=\"on\"></td></tr>");
for ($i = 0; $i < mysql_num_rows ($result); $i ++)
{
$row = mysql_fetch_object ($result);
print ("<tr>");
printf ("<td><input type='text' name='Account_numberS[$i]' value='%s' size='15'></td>", $row->Account_number);
printf ("<td><input type='text' name='usernameS[$i]' value='%s' size='15'></td>", $row->username);
printf ("<td><input type='text' name='DescriptionS[$i]' value='%s' size='15'></td>", $row->Description);
printf ("<td><input type='text' name='Card_UsedS[$i]' value='%s' size='15'></td>", $row->Card_Used);
printf ("<td><input type='text' name='BalanceS[$i]' value='%s' size='15'></td>", $row->Balance);
printf ("<td><input type='text' name='Amount_Pay_in[$i]' value='$mount_Pay_in' size='15'></td>");
printf ("<td>Modify <input type='checkbox' name='modify[$i]' value='modify'></td>");
printf ("<td>Delete <input type='checkbox' name='delete[$i]' value='delete'></td>");
printf ("<td>Checkout <input type='checkbox' name='checkout[$i]' value='checkout'></td>");
printf ("<td>Return <input type='checkbox' name='return[$i]' value='return'></td>");
print ("</tr>");
}
printf ("<tr><td colspan='6' align='center'><input type=\"submit\" value=\"Update System\"></td></tr></table></form>");
mysql_close ($link);
?>
<center>
<a href="BentleyHme.html">Home</a>
</tr>
[/php]
The img is my mysql table is that userfull, Thank you so very much.