Good morning I am seeking for a help regarding on my php code. I have a problem updating a value in database using get method.
Here is the function I have a form method which is GET and i have a forloop where in inside that loop counts the number of data with the same tracking code now. for example i have a 3 same tracking code so i have a 3 textbox and also i have a 3 submit button. Now i want to update the textbox 1 and click submit it will automatically updated.
For reference here is my code:
enter code here<form method="get" action="view-reservation.php">
<table class="table table-striped">
<tr>
<td>January</td>
<td>February</td>
<td>March</td>
<td>April</td>
<td>May</td>
<td>June</td>
<td>July</td>
<td>August</td>
<td>September</td>
<td>October</td>
<td>November</td>
<td>December</td>
<td></td>
</tr>
<?php foreach ($view as $key => $data):?>
<tr>
<td><input type="hidden" name="track" size="1" value="<?php echo $data->track?>">
<input type="hidden" name="pid" size="1" value="<?php echo $data->pid?>">
<input type="text" name="jan" size="1" value="<?php echo $data->jan?>"></td>
<td><input type="text" name="feb" size="1" value="<?php echo $data->feb?>"></td>
<td><input type="text" name="mar" size="1" value="<?php echo $data->mar?>"></td>
<td><input type="text" name="apr" size="1" value="<?php echo $data->apr?>"></td>
<td><input type="text" name="may" size="1" value="<?php echo $data->may?>"></td>
<td><input type="text" name="jun" size="1" value="<?php echo $data->jun?>"></td>
<td><input type="text" name="jul" size="1" value="<?php echo $data->jul?>"></td>
<td><input type="text" name="aug" size="1" value="<?php echo $data->aug?>"></td>
<td><input type="text" name="sep" size="1" value="<?php echo $data->sept?>"></td>
<td><input type="text" name="oct" size="1" value="<?php echo $data->oct?>"></td>
<td><input type="text" name="nov" size="1" value="<?php echo $data->nov?>"></td>
<td><input type="text" name="dec" size="1" value="<?php echo $data->dec?>"></td>
<td>
<a href="view-reservation.php?track=<?php echo $data->track?>&&pid=<?php echo $data->pid?>&&jan=<?php echo $data->jan?>"
class="label label-danger">Update Payment</a></td>
</tr>
<?php endforeach;?>
<?php endif?>
</form>
</table>
Here is my query when i execute:
if(isset($_GET['track']) && isset($_GET['pid']) && isset($_GET['jan']))
{
//
$jan = filter($_GET['jan']);
$track = filter($_GET['track']);
$pid = filter($_GET['pid']);
$query = $con->query("update payment set jan = '500' where track = '$track' and pid='$pid'") or die(mysqli_errno());
if($query)
{
echo'updated';
}
}
Related
I have this data in the oracle database photo here
I Get the data when i do while ($row = oci_fetch_array($result))
Here is my code
$query = "SELECT * FROM DEBITCREDIT WHERE DEBITCREDIT.ENTRYDATE LIKE $ENTRYDATE";
$result = oci_parse($conn, $query);
oci_execute($result);
<form method="POST" action="modal/printExpenes.php" id="SearchExpnsese" name="SearchExpnsese">
do {
<td><input type="text" name="ENTRYDATE" id="ENTRYDATE" value="<?php echo $row["ENTRYDATE"] ?>" disabled></td>
<td><input type="text" name="ACCOUNTID" id="ACCOUNTID" value="<?php echo $row["ACCOUNTID"] ?>" disabled></td>
<td><input type="text" name="REMM" id="REMM" value="<?php echo $row["REMM"] ?>" disabled></td>
<td><input type="text" name="COINPRICE" id="COINPRICE" value="<?php echo $row["COINPRICE"] ?>" disabled></td>
<td><input type="text" name="AMOUNT" id="AMOUNT" value="<?php echo $row["AMOUNT"] ?>" disabled></td>
<td><input type="text" name="FILENO" id="FILENO" value="<?php echo $FILENO = $row["FILENO"] ?>" disabled></td>
<td><input type="text" name="VOUCHER" id="VOUCHER" value="<?php echo $VOUCHER = $row["VOUCHER"] ?>" disabled></td>
<input type="submit" id="PrintExp" name="PrintExp">
} while ($row = oci_fetch_array($result));
<?php
if (isset($_POST['PrintExp'])) {
include './modal/printExpenes.php';
}
?> </form>
The output appears as in the following image photo here
The Code is working 100%
BUT
When I press print and I call my Print form
I call the data using $_Post[] as usual
Then I get this message
Warning: Undefined array key "REMM" in C:\xampp\htdocs\login\Finance\modal\printExpenes.php on line
Or Any other variables
I want to know how to print data anywhere in the while loop or any loop. Even if there Multi data From oci_fetch?
Hello Everyone,
i have built one basic HTML form using PHP for submitting data in one database table, list of variable that i use in my database table are
id, a1, a2, a3, a, a4, a5, a6, date, color, today
and i am using below HTML form to submit data in my database table
<form method="post" action="" autocomplete="off">
TODAY: <input type="text" name="today" size="5" value="<?php $theDate = date("d/m/y"); echo " $theDate"; ?>"><br>
DATE:<input type="text" name="date" size="5" align="absmiddle" value="<?php
$current_dayname = date("l");
echo $date = date("d/m/y",strtotime('monday next week')).' <br>to<br> '.date("d/m/y",strtotime("sunday next week"));
?>">
<table><tr><td><input type="text" name="a1" size="1" value="<?php echo $query2['a1']; ?>">
<input type="text" name="a2" size="1" value="<?php echo $query2['a2']; ?>">
<input type="text" name="a3" size="1" value="<?php echo $query2['a3']; ?>"></td><td>
<input type="text" name="a" size="2" value="<?php echo $query2['a']; ?>"></td><td>
<input type="text" name="a4" size="1" value="<?php echo $query2['a4']; ?>">
<input type="text" name="a5" size="1" value="<?php echo $query2['a5']; ?>">
<input type="text" name="a6" size="1" value="<?php echo $query2['a6']; ?>"></td></tr></table>
<input type="submit" name="submit">
now the issue is that i have to use three input field for values a1,a2,a3 and also for a4,a5,a6 and i want to use only one input field for these variables, so that it is easy to enter values in it..
also check image of my HTML form code
And I Want HTML form looks like below after modification:
can anyone help me in order to combine these input fields
thanks
Try this code.
It works for me(array elements can have string datatype ('words') and numeric (3, 3.4324)):
<form method="post" action="" autocomplete="off">
TODAY: <input type="text" name="today" size="5" value="<?php $theDate = date("d/m/y"); echo " $theDate"; ?>"><br>
DATE:<input type="text" name="date" size="5" align="absmiddle" value="<?php
$current_dayname = date("l");
echo $date = date("d/m/y",strtotime('monday next week')).' <br>to<br> '.date("d/m/y",strtotime("sunday next week"));
?>">
<?php if(is_string($query2['a1']) || is_numeric($query2['a1'])
&& is_string($query2['a2']) || is_numeric($query2['a2'])
&& is_string($query2['a3']) || is_numeric($query2['a3'])
&& is_string($query2['a4']) || is_numeric($query2['a4'])
&& is_string($query2['a5']) || is_numeric($query2['a5'])
&& is_string($query2['a6']) || is_numeric($query2['a6'])
&& is_string($query2['a']) || is_numeric($query2['a'])): ?>
<table>
<tr>
<td>
<input type="text" name="a1a2a3" size="3" value="<?= $query2['a1'].$query2['a2'].$query2['a3']; ?>">
</td>
<td>
<input type="text" name="a" size="2" value="<?= $query2['a']; ?>">
</td>
<td>
<input type="text" name="a4a5a6" size="3" value="<?= $query2['a4'].$query2['a5'].$query2['a6']; ?>">
</td>
</tr>
</table>
<?php endif; ?>
<input type="submit" name="submit">
this code in php gen for getting HTML snippet below
<form method="post" action="" autocomplete="off">
TODAY: <input type="text" name="today" size="5" value=" 11/10/19"><br>
DATE:<input type="text" name="date" size="5" align="absmiddle" value="14/10/19 <br>to<br> 20/10/19">
<table>
<tr>
<td>
<input type="text" name="a1a2a3" size="3" value="a1a2a3">
</td>
<td>
<input type="text" name="a" size="2" value="ww">
</td>
<td>
<input type="text" name="a4a5a6" size="3" value="a456">
</td>
</tr>
</table>
<input type="submit" name="submit">
The dynamic HTML form (with some js help) and PHP script below insert user entered values into MySQL successfully, except that all rows from the form are placed in one row on the database. What am I doing wrong?
Dynamic form HTML:
<table id="dataTable" class="form" border="4">
<tbody style="font-size:8pt">
<th>
<td align="center">Company</td>
<td align="center">Project</td>
<td align="center">Sub-Project</td>
<td align="center">Change From</td>
<td align="center">Change To</td>
<td align="center">Activity</td>
<td align="center">Responsible</td>
<td align="center">Dur</td>
</th>
<tr >
<p>
<td><input type="checkbox" required="required" name="chk[]" checked="checked" /></td>
<td><input style="width:100px" type="text" readonly="readonly" name="coa[]" value="<?php echo $co; ?>">
</td>
<td>
<select name="Projectname[]" style="font-size:10pt">
<option selected="selected" required="required">Select project</option>
<?php
foreach($proj as $item){
?>
<option value="<?php echo $item; ?>"><?php echo $item; ?></option>
<?php
}
mysqli_close($conn);
?>
</select>
</td>
<td><input style="width:100px" type="text" required="required" name="Subproj[]"></td>
<td><input style="width:130px" type="text" required="required" name="Changefrom[]"></td>
<td><input style="width:130px" type="text" required="required" name="Changeto[]"></td>
<td><input style="width:300px" type="text" required="required" name="Activity[]"></td>
<td><input style="width:90px" type="text" required="required" name="Resp[]"></td>
<td><input type="text" required="required" class="small" name="Durest[]"></td>
</p>
</tr>
</tbody>
</table>
PHP script:
<?php
include("../../db_conn_ci_i.php");
if(isset($_POST)==true && empty($_POST)==false){
$co=$_POST['co'];
$chkbox = $_POST['chk'];
$Projectname=$_POST['Projectname'];
$Subproj=$_POST['Subproj'];
$Changefrom=$_POST['Changefrom'];
$Changeto=$_POST['Changeto'];
$Activity=$_POST['Activity'];
$Resp=$_POST['Resp'];
$Durest=$_POST['Durest'];
}
$pco=implode(',',$co);
$pa=implode(',',$Projectname);
$pb=implode(',',$Subproj);
$c=implode(',',$Changefrom);
$d=implode(',',$Changeto);
$e=implode(',',$Activity);
$f=implode(',',$Resp);
$g=implode(',',$Durest);
$sql=" INSERT INTO projects (co,Projectname,Subproj,Changefrom,Changeto,Activity,Resp,Durest)
VALUES ('.$pco.','.$pa.','.$pb.','.$c.','.$d.','.$e.','.$f.','.$g.') ";
$query = mysqli_query($conn,$sql);
etc,etc
?>
Any advice?
Thank you.
You have added an extra column but not added a value for it. Since you are inserting seven columns with eight values, that's why it's not working for you. Your insert query is like below.
$sql=" INSERT INTO projects (Projectname,Subproj,Changefrom,Changeto,Activity,Resp,Durest)
VALUES ('.$pa.','.$pb.','.$c.','.$d.','.$e.','.$f.','.$g.') ";
$query = mysqli_query($conn,$sql);
I'm having some troubles getting this code to work properly. Our employees has access to our backend system on our website. This is how the input fields and such are set up:
<?
$materialer_query = $db->query("SELECT faktura_materialer.id as materialer_id, faktura.*, faktura_materialer.* FROM faktura, faktura_materialer WHERE faktura_materialer.faktura_id = faktura.id");
while($mat = $materialer_query->fetch_object()){
?>
<tr>
<td><input style="width:450px;" class="text-input" type="text" name="beskrivelse_nu" value="<? print $mat->beskrivelse; ?>"></td>
<td><input style="width:60px;" class="text-input" type="text" name="enhed_nu" value="<? print $mat->enhed; ?>"></td>
<td><input style="width:30px;" class="text-input" type="text" name="stk_nu" value="<? print $mat->stk; ?>"></td>
<td><input style="width:205px;" class="text-input" type="text" name="vejl_eks_moms_nu" value="<? print number_format($mat->vejl_eks_moms,2,",","."); ?>"></td>
<td></td>
<td><img src="images/icons/slet.gif" width="16" alt="Slet" /></td>
<input hidden name="materiale_id" value="<? print $mat->materialer_id; ?>">
</tr>
<?
}
?>
I want to be able to update every material in one page. I've tried to mess around with this, even added a hidden input field in the while loop, which contains every material id. And this is how I currently update the table:
$beskrivelse_nu = addslashes($_POST['beskrivelse_nu']);
$enhed_nu = addslashes($_POST['enhed_nu']);
$stk_nu = addslashes($_POST['stk_nu']);
$vejl_eks_moms_nu = addslashes($_POST['vejl_eks_moms_nu']);
$db->query("UPDATE faktura_materialer
SET beskrivelse = '".$beskrivelse_nu."',
enhed = '".$enhed_nu."',
stk = '".$stk_nu."',
vejl_eks_moms = '".$vejl_eks_moms_nu."'
WHERE id = '".$_POST['materiale_id']."' AND
faktura_id = '".$_faktura->faktura_id."'
");
Everytime I change something in the input fields it just change every row to the same..
I'll hope you all understand what I want :)
Because you generate the fields through the loop you end up with multiple set of fields with the same field names.
In other words, if your $materialer_query returns 4 rows, then your html will have 4 times <input hidden name="materiale_id" value="<? print $mat->materialer_id; ?>">...
If you really need to have all the fields on the same page, then you can do it in two ways:
First option. You can create separate form per row. and submit them separately.
while($mat = $materialer_query->fetch_object()){
?>
<form action="--somewhere-to-process--" method="post">
<table><tr>
<td><input style="width:450px;" class="text-input" type="text" name="beskrivelse_nu" value="<? print $mat->beskrivelse; ?>"></td>
<td><input style="width:60px;" class="text-input" type="text" name="enhed_nu" value="<? print $mat->enhed; ?>"></td>
<td><input style="width:30px;" class="text-input" type="text" name="stk_nu" value="<? print $mat->stk; ?>"></td>
<td><input style="width:205px;" class="text-input" type="text" name="vejl_eks_moms_nu" value="<? print number_format($mat->vejl_eks_moms,2,",","."); ?>"></td>
<td></td>
<td><img src="images/icons/slet.gif" width="16" alt="Slet" />
<input type="submit" value="Update">
</td>
<input hidden name="materiale_id" value="<? print $mat->materialer_id; ?>">
</tr></table>
</form>
<?
}
Second option is you create one form, but each field name is uniquer throughout the form.
Something like this:
while($mat = $materialer_query->fetch_object()){
?>
<tr>
<td><input style="width:450px;" class="text-input" type="text" name="faktura[<?=$mat->faktura_id?>][beskrivelse_nu]" value="<? print $mat->beskrivelse; ?>"></td>
<td><input style="width:60px;" class="text-input" type="text" name="faktura[<?=$mat->faktura_id?>][enhed_nu]" value="<? print $mat->enhed; ?>"></td>
<td><input style="width:30px;" class="text-input" type="text" name="faktura[<?=$mat->faktura_id?>][stk_nu]" value="<? print $mat->stk; ?>"></td>
<td><input style="width:205px;" class="text-input" type="text" name="faktura[<?=$mat->faktura_id?>][vejl_eks_moms_nu]" value="<? print number_format($mat->vejl_eks_moms,2,",","."); ?>"></td>
<td></td>
<td><img src="images/icons/slet.gif" width="16" alt="Slet" />
<input type="submit" value="Update">
</td>
<input hidden name="faktura[<?=$mat->faktura_id?>][materiale_id" value="<? print $mat->materialer_id; ?>">
</tr>
<?
}
This way your $_POST[faktura] will be an associative array with faktura-id keys and their updated value.
Scroll through the array and update the DB from each array.
Please keep in mind that qty of fields in a form is limited. So make sure not to have hundreds fields in the form :)
I have a form which loops if the value indicated is less than or equal the number of 'enrollee's needed. The while loop works perfectly with one exception, I use DOB fields which ALSO use FOR loops to display their values. If I remove the DOB fields, the form loop works fine, when left in, it errors out. Any ideas?
<form id="Enroll_Form" action="<?php $_SERVER['PHP_SELF']; ?>" method="post" name="Enroll_Form" >
<?php
$i=1;
while ($i <= ($_SESSION['Num_Members'])): {?>
<table class="demoTable">
<tr>
<td>First Name: </td>
<td><input type="text" name="F1FirstName" value="<?php echo $fields['F1FirstName']; ?>" /></td>
</tr>
<tr>
<td>Middle Initial: </td>
<td><input type="text" name="F1MI" size="2" maxlength="1" value="<?php echo $fields['F1MI']; ?>" /></td>
</tr>
<tr>
<td>Last Name: </td>
<td><input type="text" name="F1LastName" value="<?php echo $fields['F1LastName']; ?>" /></td>
</tr>
<tr>
<td>Federation No: </td>
<td><input type="text" name="F1FedNum" maxlength="10" value="<?php echo $fields['F1FedNum']; ?>" /></td>
</tr>
<tr>
<td>SSN: </td>
<td><input type="text" name="F1SSN1" size="3" maxlength="3" value="<?php echo $fields['F1SSN1']; ?>" /> -
<input type="text" name="F1SSN2" size="2" maxlength="2" value="<?php echo $fields['F1SSN2']; ?>" /> -
<input type="text" name="F1SSN3" size="4" maxlength="4" value="<?php echo $fields['F1SSN3']; ?>" />
</td>
</tr>
<tr>
<td>Date of Birth</td>
<td>
<select name="F1DOB1">
<option value="">Month</option>
<?php
for ($i=1; $i<=12; $i++)
{
echo "<option value='$i'";
if ($fields["F1DOB1"] == $i)
echo " selected";
echo ">$i</option>";
}
?>
</select> /
<select name="F1DOB2">
<option value="">Day</option>
<?php
for ($i=1; $i<=31; $i++)
{
echo "<option value='$i'";
if ($fields["F1DOB2"] == $i)
echo " selected";
echo ">$i</option>";
}
?>
</select> /
<select name="F1DOB3">
<option value="">Year</option>
<?php
for ($i=date('Y'); $i>=1900; $i--)
{
echo "<option value='$i'";
if ($fields["F1DOB3"] == $i)
echo " selected";
echo ">$i</option>";
}
?>
</select>
</td>
</tr>
<tr>
<td>Address: </td>
<td><input type="text" name="F1Address" value="<?php echo $fields['F1Address']; ?>" /></td>
</tr>
<tr>
<td>City: </td>
<td><input type="text" name="F1City" value="<?php echo $fields['F1City']; ?>" /></td>
</tr>
<tr>
<td>State: </td>
<td><select name="F1State"><option value="">Choose a State</option><?php showOptionsDrop($states_arr, null, true); ?></select></td>
</tr>
<tr>
<td>Zip Code: </td>
<td><input type="text" name="F1Zip" size="6" maxlength="5" value="<?php echo $fields['F1Zip']; ?>" /></td>
</tr>
<tr>
<td>Contact Telephone No: </td>
<td>( <input type="text" name="F1Phone1" size="3" maxlength="3" value="<?php echo $fields['F1Phone1']; ?>" /> )
<input type="text" name="F1Phone2" size="3" maxlength="3" value="<?php echo $fields['F1Phone2']; ?>" /> -
<input type="text" name="F1Phone3" size="4" maxlength="4" value="<?php echo $fields['F1Phone3']; ?>" />
</td>
</tr>
<tr>
<td>Email:</td>
<td><input type="text" name="F1Email" value="<?php echo $fields['F1Email']; ?>" /></td>
</tr>
</table>
<br />
<?php } $i++; endwhile; ?>
<div align="right"><input class="enrbutton" type="submit" name="submit" value="Continue" /></div>
</form>
You are using $i in your while loop, and in all of your for loops. You need to change it to something else.
That is probably causing you some problems (not to mention it being terribly hard to understand)