I need to show my billing history, so user can automatically submit by clicking submit. But instead of showing all transactions, I only have to show for each billing_name, so I should use SELECT DISTINCT right?
<?php
$query3 = "SELECT DISTINCT billing_name, billing_reference_num FROM billing_history";
$result3 = mysqli_query($link, $query3) or die(mysqli_error($link));
while ($row3 = mysqli_fetch_array($result3)) {
$billing_name = $row3['billing_name'];
$billing_reference_num = $row3['billing_reference_num'];
?>
<td><?php echo $billing_name ?></td>
<td><?php echo $billing_reference_num ?></td>
<?php
$queryBill = "SELECT * FROM billing_history WHERE billing_name = '$billing_name'";
$resultBill = mysqli_query($link, $queryBill) or die(mysqli_error($link));
while ($row4 = mysqli_fetch_array($resultBill)) {
$billing_name_id = $row4['billing_name_id'];
$account_id = $row4['account_id'];
$account_number = $row4['account_number'];
}
?>
<td><input type="text" name="transaction_amount"/></td>
<td><input type="submit" value="Submit"/></td>
<input type="hidden" name="billing_name_id" value="<?php echo $billing_name_id ?>"/>
<input type="hidden" name="billing_name" value="<?php echo $billing_name ?>"/>
<input type="hidden" name="billing_reference_num" value="<?php echo $billing_reference_num ?>"/>
<input type="hidden" name="account_number" value="<?php echo $account_number ?>"/>
<input type="hidden" name="account_id" value="<?php echo $account_id ?>"/>
Related
So I've been doing this school project and need to make it so I can edit whatever is in the table. Whenever i click on "Edit" it redirects me correctly but in the form it says there is an undefined variable eventhough that variable is used pretty much everywhere.
Here is some code of the table:
<table style='margin-left:auto ; margin-right:auto;'>
<tr>
<th>#</th>
<th>Name</th>
<th>Zeit</th>
<th>Datum</th>
<th>Titel</th>
<th>Inhalt</th>
<th>Ort</th>
</tr>
<?php
if($stmt=$db->prepare("SELECT * FROM terminkalender")) {
$stmt->execute();
$stmt->store_result();
$zeilen = $stmt->num_rows();
$stmt->close();
}else {
$zeilen = 0;
}
if($zeilen > 0) {
//nur wenn Einträge, dann ausgeben
if($stmt = $db->prepare("SELECT * FROM terminkalender ORDER BY zeit,datum DESC")) {
$stmt->execute();
$stmt->bind_result($id,$name,$zeit,$datum,$ort,$titel,$inhalt);
$stmt->store_result();
//Ausgabe starten
while($stmt->fetch()){
echo "<tr>";
?>
<td><?php echo $id ;?></td>
<td><?php echo htmlspecialchars($name) ;?></td>
<td><?php echo htmlspecialchars($datum) ;?></td>
<td><?php echo htmlspecialchars($zeit) ;?></td>
<td><?php echo htmlspecialchars($ort) ;?></td>
<td><?php echo htmlspecialchars($titel) ;?></td>
<td><?php echo htmlspecialchars($inhalt); ?></td>
<td><a href='edit.php?id=<?php echo $id;?>'>Edit</a></td>
<td><a href='delete.php?id=<?php echo $id;?>'>Delete</a></td>
<?php
echo "</tr>" ;
}
}
}
?>
</table>
and here for the edit.php file:
<?php
include("./config/connect.inc.php");
$id = $_GET['id']; // get id through get string
$result=mysqli_query($db,"SELECT * FROM terminkalender WHERE id=$id");
if(isset($_POST['update'])) {
$name=$_POST['name'];
$datum=$_POST['datum'];
$zeit=$_POST['zeit'];
$ort=$_POST['ort'];
$titel=$_POST['titel'];
$inhalt=$_POST['inhalt'];
$result = "UPDATE terminkalender
SET name='$name',
datum='$datum',
zeit='$zeit',
ort='$ort',
titel='$titel',
inhalt='$inhalt'
WHERE id=$id";
header("location: ausgabe.php");
}
?>
<form name="form" method="POST" action="edit.php">
<input type="text" name="name" value="<?php echo $name; ?>" Required>
<input type="date" name="datum" value="<?php echo $datum; ?>" Required>
<input type="time" name="zeit" value="<?php echo $zeit; ?>" Required>
<input type="text" name="ort" value="<?php echo $ort; ?>" Required>
<input type="text" name="titel" value="<?php echo $titel; ?>" Required>
<input type="text" name="inhalt" value="<?php echo $inhalt; ?>" Required>
<input type="hidden" name="id" value="<?php echo $_GET['id']; ?>">
<input type="submit" name="update" value="Update">
</form>
Ẁould be really awesome if anyone could help. Thanks is advance!
Maybe you can try using isset function of php to check if that variable contains a value or not for more details check:-https://www.stechies.com/notice-undefined-variable-in-php/
I am making a book management system.I have a return button ,with that button user can return books.
Here is my release-books.php:
<?php
$sql_select = "SELECT * FROM carti ORDER BY titlu";
$rezultat = mysqli_query($conn, $sql_select);
if (mysqli_num_rows($rezultat) > 0) {
while ($row = mysqli_fetch_assoc($rezultat)) {
$disabled = $row['stoc'] > 0 ? "" : "disabled"; ?>
<tr><td><input type="submit" name="id" value="<?php echo $row['idCarte']; ?>" <?php echo $disabled; ?> formaction="imprumutare.php"></input></td>
<td><input type="submit" name="returnare" value="<?php echo $row['idCarte']; ?>" formaction="returnare_carte.php"></input>
</td>
<td><input type="text" name="nume" value="<?php echo $row['titlu']; ?>" ></input></td>
<td><input type="text" name="" value="<?php echo $row['autor']; ?>"></input></td>
<td><input type="text" name="" value="<?php echo $row['editura']; ?>"></input></td>
<td><input type="text" name="" value="<?php echo $row['categorie']; ?>"></input></td>
<td><input type="text" name="" value="<?php echo $row['data_adaugarii']; ?>"></input></td>
<td><input type="text" name="" value="<?php echo $row['stoc']; ?>"></input></td>
</tr>
<?php
}
}
?>
And here is my borrowing.php
include('conexiune.php');
//sfarsit if
//Imprumutare
if (isset($_POST['id'])) {
$identificator = $_POST['id'];
$carte_nume = $_POST['nume'];
$current_date = date('y:m:d');
$current_date_plus_14days = date('y:m:d', strtotime("+14 days"));
$nume_carte = $_POST['nume'];
$insert_in_imprumuturi = "INSERT INTO imprumuturi(idc,nume_carte,data,termen_returnare,carti_imprumutate) VALUES('$identificator','$carte_nume','$current_date','$current_date_plus_14days','1')";
mysqli_query($conn, $insert_in_imprumuturi) or die(mysqli_error($conn));
$sql_rezervare = "UPDATE carti SET stoc=stoc-1 WHERE iDCarte='$identificator' ";
if (mysqli_query($conn, $sql_rezervare)) {
header('Refresh:0,url=emitere_carti.php');
} else {
die(mysqli_error($conn));
}
}
But I do not know how to disable the return button when the returned books volume is equal or greater that the originial volume
Can somone help me?
Check If your books volume is equal or greater than original volume, if it is. Use PHP echo to disable the Return Button.
<button type="submit" name="return"
<?php
if($returned_books_volume >= $original_books_volume){
echo 'disabled';
}
?>
>Return</button>
I have a while loop. It is within a form.I want to insert all rows from while loop when submitting submit button. Below is the code of while loop.
<form method="POST" action="insert.php" n>
<table>
<?php
$i =0;
$link = mysqli_connect('localhost', 'root', '', 'shibu');
$sql = "select `cus_id`, `mobile`, `date`, `time`,
sum(`d1` + `d2` + `d3`) as `credit`,
from `finale`;
$result=mysqli_query($link, $sql);
$count = mysqli_num_rows($result);
if($count == 0){
?>
<tr>
<th><?php echo 'No Records Founds!' .mysqli_error($link); ?></th>
</tr>
<?php
}else{
while($sql_result = mysqli_fetch_assoc($result)){
?>
<tr>
<td><?php echo $i += 1; ?></td>
<td><input type="text" name="cus_id" value="<?php echo $sql_result['cus_id']; ?>" ></td>
<td><input type="text" name="mobile" value="<?php echo $sql_result['mobile']; ?>" ></td>
<td><input type="text" name="date" value="<?php echo $sql_result['date']; ?>" ></td>
<td><input type="text" name="time" value="<?php echo $sql_result['time']; ?>"</td>
<td><input type="text" name="credit" value="<?php echo $sql_result['credit']; ?>"></td>
</tr>
<?php
}
}
?>
</table>
<input name="submit" type="submit" />
</form>
This is my insert query.
<?php
$link = mysqli_connect('localhost', 'root', '', 'shibu');
$stmt = mysqli_prepare($link, "INSERT INTO single
(`cus_id`, `mobile`, `date`, `time`, `credit`) VALUES (?,?,?,?,?)");
mysqli_stmt_bind_param($stmt, 'isssi', $cus_id, $mobile, $date, $time, $credit);
foreach ((array)$_POST['cus_id'] as $i => $cus_id) {
$mobile = $_POST['mobile'];
$date = $_POST['date'];
$time = $_POST['time'];
$credit = $_POST['credit'];
mysqli_stmt_execute($stmt);
}
if(!$stmt){
echo "error". mysqli_error($link);
}
My problem is when I enter submit button, only last row enters not the whole rows.
I need your help heartily.
In your html code you need to have input names defined as array.
Like
<td><input type="text" name="cus_id[]" value="<?php echo $sql_result['cus_id']; ?>" ></td>
<td><input type="text" name="mobile[]" value="<?php echo $sql_result['mobile']; ?>" ></td>
<td><input type="text" name="date[]" value="<?php echo $sql_result['date']; ?>" ></td>
<td><input type="text" name="time[]" value="<?php echo $sql_result['time']; ?>"</td>
<td><input type="text" name="credit[]" value="<?php echo $sql_result['credit']; ?>"></td>
And while using them in php you need to loop them and run insert query
foreach ($_POST['cus_id'] as $i => $value) {
$cus_id = $_POST['cus_id'][$i];
$mobile = $_POST['mobile'][$i];
$date = $_POST['date'][$i];
$time = $_POST['time'][$i];
$credit = $_POST['credit'][$i];
// Yourinsert query
}
Please move your
mysqli_stmt_bind_param
line into foreach loop, just above
mysqli_stmt_execute
line.
I am trying to update mysql data from user input displayed on a table, i have used the following code, even though the name is set and the value is set when i click update the code states "Undefined index: LHA" but as you can see i have declared this along with Work_date, LHA, AAS, LSA, AAH (the fields throwing the undefiend index errors) I also want the unefcted data to remain the same in the mysql database as apposed to settting it to blank! This is the HTML (A while statement to fetch the data to populate the value fields in the html table)
while($row = $sth->fetch()) { ?>
<form action='../action.php' method='post'>
<tr>
<td> <?php echo $row['Name'] ?></td>
<td> <input name='car' id='car' value="vv1"><br/><br/></td>
<td> <select name='Night' id='Night'><option selected='selected' value='no'>No</option><option value='Yes'>Yes</option></select> <br/><br/></td>
<td> <input class='text' name="Siteid" type="text" value="<?php echo $row['Workbook ID']; ?>" /> <br/><br/></td>
<td> <input class='datepicker' name="Work_date" type="text" value="<?php echo date('l, F d, Y', strtotime($row['Work Date'])) ?>" placeholder="Select Date!"/><br/><br/></td>
<td> <input class='timepicker' name="LHA" type="text" value="<?php echo $row['LHA'] ?>" /><br/><br/></td>
<td> <input class='timepicker' name="AAS" type="text" value="<?php echo $row['AAS'] ?>" /><br/><br/></td>
<td> <input class='timepicker' name="LSA" type="text" value="<?php echo $row['LS'] ?>" /><br/><br/></td>
<td> <input class='timepicker' name="AAH" type="text" value="<?php echo $row['AAH'] ?>" /><br/><br/></td>
<td> <input name="Bonus" type="text" value="<?php echo $row['Bonus']; ?>" /> <br/><br/></td>
<td> <input name="Work_Completed" type="text" value="<?php echo $row['Work Completed']; ?>" /> <br/><br/></td>
<td> <input name="BH" type="text" value="<?php echo $row['Hours']; ?>" /><br/><br/></td>
<input type='hidden' name='PID' value="<?php echo $row['PID'];?>" />
<td><input type='submit' name='delete_timesheet' value='delete' /></td>
<td><input type='submit' class='btn btn-default' name='update_timesheet' value='Update' /></td>
</tr>
</form>
<?php
}
Just to mention my query and field settings work perfectly on XAMPP but not when online, this is my PHP
if(isset($_POST['update_timesheet'])) {
$a = $_POST['car'];
$b = $_POST['Night'];
$c = $_POST['Siteid'];
$d = $_POST['Work_date'];
$e = $_POST['LHA'];
$f = $_POST['AAS'];
$g = $_POST['LSA'];
$h = $_POST['AAH'];
$i = $_POST['Bonus'];
$j = $_POST['BH'];
$l = $_POST['PID'];
$Paid = create_paid($e, $f, $g, $h);
$stmt = "UPDATE data SET Car = ?, Night = ?, `Workbook ID` = ?, `Work Date` = ?, LHA = ?, AAS = ? , LS = ? , AAH = ? , Bonus = ?, `Work Completed` = ?, Hours = ? WHERE PID = ? ";
$y = $pdo->prepare($stmt);
$y->execute(array($a,$b, $c, $d, $e, $f, $g, $h, $i, $j, $Paid, $l));
header('Location: ' . $_SERVER['HTTP_REFERER']);
}
new guy here!
I am building a custom shopping cart driven by mysql and i am trying to update my cart item by item in terms of quantity. It seems that i am doing something wrong because when i try to update the quantity it only update the last item. I am posting the code below. Any help would be appreciated. Thanks in advance.
1.cart.php:
$sql = "select * from orders";
$result = mysql_query($sql);
$num = mysql_num_rows($result);
echo "Στοιχεία: ".$num;
?>
<form name="cart" method="post" action="updatecart.php">
<table border="2">
<tr>
<td>Α/Α</td>
<td>img_name</td>
<td>Reprints</td>
<td>Color</td>
</tr>
<?php
if($num){
while ($row = mysql_fetch_array($result)){
?>
<tr>
<td><?php echo $row['item_id']; ?></td>
<td><?php echo $row['img_name']; ?></td>
<td><input type="number" name="quantity" value="<?php echo $row['quantity']; ?>"></td>
<input type="hidden" name="item_id" value="<? echo $row['item_id']; ?>">
<td><?php echo $row['color']; ?></td>
</tr>
<?php
}
}
?>
</table>
<input type="submit" name="update" value="Update Cart" />
<input type="button" name="2checkout" value="Proceed to Checkout" />
</form>
2.updatecart.php
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<?php
$database_name = "vog";
$conn = mysql_connect("localhost","root","toor");
mysql_select_db($database_name);
$num = 2; //na to ferw me session meta edw!
if(isset($_POST['update'])){
$item_id = $_POST['item_id'];
$i=1;
while($i<=$num){
$item_id = $_POST['item_id'][$i];
$quantity = $_POST['quantity'];
$sql2 = "update orders SET quantity = '$quantity' where item_id = '$item_id' ";
$result2 = mysql_query($sql2) or die ("Error in query: $result2");
$i++;
}
}
if(isset($result2)){
header("Location:cart.php");
}
?>
So far it updates just the last record.
Your problem is with the names of the fields in your HTML form:
<input type="number" name="quantity" value="<?php echo $row['quantity']; ?>">
<input type="hidden" name="item_id" value="<? echo $row['item_id']; ?>">
I think you meant to call them quantity[] and item_id[] instead, so they will and up as arrays in your $_POST variable later on, now they overwrite eachother, making $_POST['item_id'] only contain the last id in the database.
in #1.cart.php use the inputs as array:
<input type="number" name="quantity[<?php echo $row['item_id']; ?>]" value="<?php echo $row['quantity']; ?>">
<input type="hidden" name="item_id[<?php echo $row['item_id']; ?>]" value="<? echo $row['item_id']; ?>">
and in #2.updatecart.php: process it like
foreach($_POST['item_id'] as $key => $id){
$item_id = $id;
$quantity = $_POST['quantity'][$key];
$sql2 = "update orders SET quantity = '$quantity' where item_id = '$item_id' ";
$result2 = mysql_query($sql2) or die ("Error in query: $result2");
$i++;
}
You need to tell PHP that you're using an array for your submitted form items. The way to do this is to make the name of each input quantity[]. You can also place the item ID directly in the array as a key. In cart.php you can do this in your loop:
<input type="number" name="quantity[<?php echo $row['item_id']; ?>]"
value="<?php echo $row['quantity']; ?>"/>
In effect, this will putput something like:
<input type="number" name="quantity[2]" value="1" />
<input type="number" name="quantity[4]" value="1" />
<input type="number" name="quantity[8]" value="2" />
i.e. 1 of item 2, 1 of item 4 and 2 of item 8.
Then, in updatecart.php you can read in the array and process it in a loop.
if(isset($_POST['update'])){
foreach ($_POST['quantity'] as $item_id => $item_qty) {
$item_id = (int)$item_id;
$item_qty = (int)$item_qty;
$sql2 = "update orders SET quantity = '$item_qty' where item_id = '$item_id' ";
mysql_query($sql2);
}
}