This is the table form which i will select the row to edit by using Button Edit
$query = "SELECT * FROM tbl_document LIMIT $start, $end";
$result = mysqli_query($con,$query);
echo "<table border='1' width='300' height='160' align = center id='result'>";
echo '<tr>
<th width="80">ID</th>
<th width="200">Title</th>
<th width="260">Presented To</th>
<th width="260">Presented By</th>
<th width="160">Date Submitted</th>
<th>Location</th>
<th width="17%">Option</th>
</tr>';
while($row = mysqli_fetch_array($result)){
echo "<tr align = center >";
echo "<td width='20' height='60'>" .$row['ID']. "</td>";
echo "<td width='120' height='60'>" .$row['Title']. "</td>";
echo "<td>" .$row['Presented_To']. "</td>";
echo "<td>" .$row['Presented_By']. "</td>";
echo "<td>" .$row['Date_Submitted']. "</td>";
echo "<td>" .$row['Location']. "</td>";
echo "<td width='17%'>";
?>
<p>
<button onclick="document.getElementById('edtID').style.display='block'" value="<?php echo $row['ID']; ?>" class="w3-btn w3-blue w3-border-large w3-circle" id="edit" name="edit" style="width:60%"><i class="fa fa-edit"></i> Edit</button>
This is the second code this form is modal which i click the button from the table and the modal show and you can edit but what is missing of my code?
<form method="post" action="<?php $_SERVER['PHP_SELF'];?>">
<p>
<label class="w3-label w3-text-black"><strong>Title:</strong></label>
<input class="w3-input w3-hover-light-blue w3-animate-input w3-border-large w3-light-grey" style="width:100%" type="text" id="title" name="title" placeholder="Title" value=<?php $row['Title']; ?>required></span>
</p>
</form>
On your second form (your modal), I see no echo to display the value of your title
<form method="post" action="<?php $_SERVER['PHP_SELF'];?>">
<p>
<label class="w3-label w3-text-black"><strong>Title:</strong></label>
<input class="w3-input w3-hover-light-blue w3-animate-input w3-border-large w3-light-grey" style="width:100%" type="text" id="title" name="title" placeholder="Title" value=<?php echo $row['Title']; ?>required></span>
</p>
</form>
Also, for your first form, you can write it this way
<table border='1' width='300' height='160' align=center id='result'>
<tr>
<th width="80">ID</th>
<th width="200">Title</th>
...
</tr>
<?php
while($row = mysqli_fetch_array($result))
{
echo "<tr align = center >";
echo "<td width='20' height='60'>" .$row['ID']. "</td>";
echo "<td width='120' height='60'>" .$row['Title']. "</td>";
...
?>
<p>
<button onclick="document.getElementById('edtID').style.display='block'" value="<?php echo $row['ID']; ?>" class="w3-btn w3-blue w3-border-large w3-circle" id="edit" name="edit" style="width:60%">
<i class="fa fa-edit"></i> Edit
</button>
</p>
<?php
}
?>
And finally, you should start using PDO for everything related to the database.
Related
Form with download.php - does not work
Form with action with remove.php - works
Am I missing some little thing?
<table id="mytable1" width="80%" class="text-center table table-striped table-bordered table-Responsive ">
<thead>
<th>File Name</th>
<th>File Type</th>
<th>File Size(KB)</th>
<th>Remove</th>
<th>Download</th>
</thead>
</tr>
<?php
while($item = mysql_fetch_array($result1)) {
echo "<tr>";
echo "<td>".$item['file_name']."</td>";
echo "<td>".$item['file_type']."</td>";
echo "<td>".$item['file_size']."</td>";
// this command does not work but the next echo works - why?
echo "<td><form action='download.php' method='GET'><input name='filename' type='hidden' value='".$item['file_name']."'/><button class='btn btn-danger btn-xs' type='submit' value='down'/><span class='glyphicon glyphicon-trash'></span></form></td>";
echo "<td><form action='remove.php' method='GET'><input name='filename' type='hidden' value='".$item['file_name']."'/><button class='btn btn-primary btn-xs' type='submit' value='del'/><span class='glyphicon glyphicon-download'></span></form></td>";
echo "</tr>";
}
echo "</table>";
?>
Just want to know how to find the match value on the dropdown list and display the value as current selected for update.
this is my table query and displayed on page with update link beside each row. All update link is working and the value displayed on hidden textbox. My problem is just on one column $trandescription, this will be post on dropdown.
this is my display table.
while($row = mysql_fetch_array($query))
{
echo "
<tr>
<td style='border:1px solid; color:gray' width='145px' align='center'>".$row['patientid']."</td>
<td style='border:1px solid; color:gray' width='145px' align='center'>".$row['trandate']."</td>
<td style='border:1px solid; color:gray' width='600px'>".$row['trandescription']."</td>
<td style='border:1px solid; color:gray' width='90px' align='center'>".$row['tranquantity']."</td>
<td style='border:1px solid; color:gray' width='90px' align='right'>".number_format($row['tranunitprice'],2)."</td>
<td style='border:1px solid; color:gray' width='150px' align='right'>".number_format($row['tranamount'],2)."</td>
<td style='border:1px solid; color:gray'><a href='updatebillindex.php?update=$row[id]'>update</a></td>
<td style='border:1px solid; color:gray'><button class='btn btn-default btn-sm';><a href='updatebillindex.php?update=$row[0]'>edit
<span class='glyphicon glyphicon-trash'></span></a></button></td>
</tr> ";
this is my update page
<?php
if (isset($_GET['update']))
{
$id = $_GET['update'];
$query = mysql_query("SELECT * FROM transaction where id = '$id'") or die ("could not search");
$count = mysql_num_rows($query);
while ($rows = mysql_fetch_array($query)) {
$id = $rows['id'];
$tranid = $rows['tranid'];
$trandate = $rows['trandate'];
$patientid = $rows['patientid'];
$transactiontype = $rows['transactiontype'];
$trandescription = $rows['trandescription'];
$tranquantity = $rows['tranquantity'];
$tranunitprice = $rows['tranunitprice'];
$tranamount =$rows['tranamount'];
$gettrandescription = $rows['trandescription'];
}
}
?>
<form action="billindex.php" method="POST">
<input type="hidden" name="id" value="<?php echo "$id"; ?>">
<input type="hidden" name="tranid" value="<?php echo "$tranid"; ?>">
<input type="hidden" name="patientid" value="<?php echo "$patientid"; ?>">
<input type="hidden" name="trandate" value="<?php echo "$trandate"; ?>">
<input type="hidden" name="transactiontype" value="<?php echo "$transactiontype"; ?>">
<input type="text" name="trandescription" value="<?php echo "$trandescription"; ?>">
<input type="hidden" name="tranquanity" value="<?php echo "$tranquantity"; ?>">
<input type="hidden" name="tranunitprice" value="<?php echo "$tranunitprice"; ?>">
<input type="hidden" name="tranamount" value="<?php echo "$tranamount"; ?>">
<input type="submit" name="update" value="Update">
</form>
<?php
echo "$trandescription"; // find the match value on dropdown list and display this value.
?>
this is my dropdown list on the update page
<div class="panel panel-default">
<div class="panel-heading" role="tab" id="headingTwo">
<h4 class="panel-title">
<a class="collapsed" role="button" data-toggle="collapse" data-parent="#accordion" href="#collapseTwo" aria-expanded="false" aria-controls="collapseTwo">
Medicine
</a>
</h4>
</div>
<div id="collapseTwo" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingTwo">
<div class="panel-body">
<form action="transaction.php" method="POST">
<div class="col-md-6">
<div class="panel panel-info">
<div class="panel-heading"><h7>Medicine Type : </h7></div>
<div class="panel-body">
<select name="selectmedicine" class="form-control col-sm-4" id="medicinename">
<option id="0" style="width:100px"></option>
<?php
$medicine = mysql_query("SELECT * FROM medicine");
while ($row = mysql_fetch_array($medicine)) {
echo '<option id="' . $row['medicinename'] . '"';
echo ' value="' . $row['medicineid'] . '"';
if($row['medicineid'] == $row['medicinename']) {
echo ' selected="selected"';
}
echo '>';
echo $row['medicinename'];
echo '</option>';
}
?>
</select>
</div>
</div>
</div>
first,I have table display from database, in each row it has update button.
second, i have a four (4) collapsible select option form.
third, the select option form has value from database. this value is also present in the column on the table above(first).
Now what i want is when i update the value from the row on the table, the collapsible form will open then the value from the table will display on the select option form.
Here's my code. the code below cant open the collapsible form and display the value on the select option form.
displaytable.php
<?php
$output='';
$noresult='';
if (isset($_POST['search']))
{
$globalpid = $_POST['search'];
$query = mysql_query("SELECT * FROM transaction where patientid ='$globalpid' order by trandate asc") or die ("could not search");
$count = mysql_num_rows($query);
$globalpid = mysql_real_escape_string($globalpid);
if($count == '' && $countname==0)
{
?>
<?php require_once 'search.php'; ?>
<div class="container" style="padding-left:30px">
<br><p><font color="#0B3861"><?php echo "There was no search results!"; ?> </font>
</div>
</div>
<?php }else{
?>
<?php
$total = '';
$add=mysql_query("SELECT SUM(tranamount) from transaction where patientid = $globalpid");
while($row=mysql_fetch_array($add))
{
$totalamount=$row['SUM(tranamount)'];
}
require_once 'transactionheadermenu.php';
?>
<div class="container" style="padding-top:0px; padding-left:30px; padding-right:30px;">
<div class="panel panel-default">
<div class="panel-heading"><h3 class="panel-title"><font color="#2B547E"><?php echo "$outputname";?></font></h3></div>
<div class="panel-body">
<?php require_once 'billpatientquery.php';?>
<?php
echo "<table class='table table-hover';>
<tr>
<td style='border:1px solid; color:gray' width='145px' align='center'>Patient ID</td>
<td style='border:1px solid; color:gray' width='145px' align='center'>Date</td>
<td style='border:1px solid; color:gray' width='600px' align='center'>Item / Description</td>
<td style='border:1px solid; color:gray' width='90px' align='center'>Quantity</td>
<td style='border:1px solid; color:gray' width='90px' align='center'>Price</td>
<td style='border:1px solid; color:gray' width='150px' align='center'>Amount</td>
<td style='border:1px solid; color:gray' width='30px' align='center'>Update</td>
<td style='border:1px solid; color:gray' width='30px' align='center'>Delete</td>
</tr>";
while($row = mysql_fetch_array($query))
{
echo "
<tr>
<td style='border:1px solid; color:gray' width='145px' align='center'>".$row['patientid']."</td>
<td style='border:1px solid; color:gray' width='145px' align='center'>".$row['trandate']."</td>
<td style='border:1px solid; color:gray' width='600px'>".$row['trandescription']."</td>
<td style='border:1px solid; color:gray' width='90px' align='center'>".$row['tranquantity']."</td>
<td style='border:1px solid; color:gray' width='90px' align='right'>".number_format($row['tranunitprice'],2)."</td>
<td style='border:1px solid; color:gray' width='150px' align='right'>".number_format($row['tranamount'],2)."</td>
<td style='border:1px solid; color:gray'><a href='updatebillindex.php?update=$row[id]'>update</a></td>
<td style='border:1px solid; color:gray'><button class='btn btn-default btn-sm';><a href='updatebillindex.php?update=$row[0]'>edit
<span class='glyphicon glyphicon-trash'></span></a></button></td>
</tr> ";
}
echo "</table>";
?>
</div>
</div>
</div>
<?php }
} ?>
updatebillindex.php
?php
if (isset($_GET['update']))
//
{
$id = $_GET['update'];
// //$tranid = $_POST['update'];
//$patientid = $_POST['update'];
//$trandate = $_POST['update'];
//$getname = $_POST['update'];
$query = mysql_query("SELECT * FROM transaction where id = '$id'") or die ("could not search");
$count = mysql_num_rows($query);
while ($rows = mysql_fetch_array($query)) {
$id = $rows['id'];
$tranid = $rows['tranid'];
$trandate = $rows['trandate'];
$patientid = $rows['patientid'];
$transactiontype = $rows['transactiontype'];
$trandescription = $rows['trandescription'];
$tranquantity = $rows['tranquantity'];
$tranunitprice = $rows['tranunitprice'];
$tranamount =$rows['tranamount'];
$gettrandescription = $rows['trandescription'];
}
}
if (isset($_POST['selectmedicine'])) {
$gettrandescription=$_POST['medicineid'];
}
if (isset($_POST['selectroomquantity'])) {
$tranquantity=$_POST['quantity'];
}
?>
<script type="text/javascript">
$('#collapseone').collapseone({
toggle: true
});
</script>
<option value="<?php echo $trandescription; ?>" <?php if($trandescription==$gettrandescription){ echo "selected";} ?> ><?php echo $gettrandescription; ?></option>
<option value="<?php echo $tranquantity; ?>" <?php if($tranquantity==$tranquantity){ echo "selected";} ?> ><?php echo $tranquantity; ?></option>
<form action="billindex.php" method="POST">
<input type="hidden" name="id" value="<?php echo "$id"; ?>">
<input type="hidden" name="tranid" value="<?php echo "$tranid"; ?>">
<input type="hidden" name="patientid" value="<?php echo "$patientid"; ?>">
<input type="hidden" name="trandate" value="<?php echo "$trandate"; ?>">
<input type="hidden" name="transactiontype" value="<?php echo "$transactiontype"; ?>">
<input type="hidden" name="trandescription" value="<?php echo "$trandescription"; ?>">
<input type="hidden" name="tranquanity" value="<?php echo "$tranquantity"; ?>">
<input type="hidden" name="tranunitprice" value="<?php echo "$tranunitprice"; ?>">
<input type="hidden" name="tranamount" value="<?php echo "$tranamount"; ?>">
<input type="submit" name="update" value="Update">
</form>
<div class="panel panel-default">
<div class="panel-heading" role="tab" id="headingTwo">
<h4 class="panel-title">
<a class="collapsed" role="button" data-toggle="collapse" data-parent="#accordion" href="#collapseTwo" aria-expanded="false" aria-controls="collapseTwo">
Medicine
</a>
</h4>
</div>
<div id="collapseTwo" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingTwo">
<div class="panel-body">
<form action="transaction.php" method="POST">
<div class="col-md-6">
<div class="panel panel-info">
<div class="panel-heading"><h7>Medicine Type : </h7></div>
<div class="panel-body">
<select name="selectmedicine" class="form-control col-sm-4" id="medicinename">
<option id="0" style="width:100px"></option>
<?php
$medicine = mysql_query("SELECT * FROM medicine");
while ($row = mysql_fetch_array($medicine)) {
echo '<option id="' . $row['medicinename'] . '"';
echo ' value="' . $row['medicineid'] . '"';
if($row['medicineid'] == $row['medicinename']) {
echo ' selected="selected"';
}
echo '>';
echo $row['medicinename'];
echo '</option>';
}
?>
</select>
</div>
</div>
</div>
<div class="col-md-6">
<div class="panel panel-info">
<div class="panel-heading panel-height:20px":><h7>Quantity : </h7></div>
<div class="panel-body">
<select name="selectmedicinequantity" class="form-control col-md-4" id="quantityname">
<option id="0" style="width:100px"></option>
<?php
$medicinequantity = mysql_query("SELECT * FROM quantity");
while ($displayquantity = mysql_fetch_array($medicinequantity)) {
$quantityid = $displayquantity['id'];
$quantityname = $displayquantity['quantityname'];
//$quantityprice = $displayquantity['quantityprice'];
?>
<option id=" <?php echo $displayquantity['quantityid']; ?>"><?php if($displayquantity['quantityid'] == $displayquantity['quantityname']) echo 'selected="selected"'; ?><?php echo $displayquantity['quantityname'] ?></option>
<?php
}
?>
</select>
</div>
</div>
</div>
I am having trouble with a part of my code. I want the checkbox in the last column to be checked if the corresponding DB value is 1, but something keeps going wrong with my code, anyone who sees what's wrong? It's probably very simple but I can't find it.
<?php
$sql = "SELECT * FROM registered ORDER BY datum";
$myData=mysql_query($sql,$con) ;
?>
<table width="1100" border="1">
<tr>
<th style="text-align:center; padding:0 10px">naam</th>
<th style="text-align:center; padding:0 10px">betaald?</b></th>
</tr>
<?php
$betaald = $record['betaald'];
while($record = mysql_fetch_array($myData)) {
echo "<tr>";
echo "<td>" . $record['naam'] . "</td>";
echo "<td> <input type='checkbox' name='betaald' id='betaald' value='1' ". echo ($betaald==1 ? 'checked' : ''); . " ></td>";
echo "</tr>";
}
mysql_close($con);
?>
<?php
$sql = "SELECT * FROM registered ORDER BY datum";
$myData = mysql_query($sql, $con);
?>
<table width="1100" border="1">
<tr>
<th style="text-align:center; padding:0 10px">naam</th>
<th style="text-align:center; padding:0 10px">betaald?</b></th>
</tr>
<?php while ($record = mysql_fetch_array($myData)) { ?>
<tr>
<td><?php echo $record['naam'] ?></td>
<td>
<input type='checkbox' name='betaald' id='betaald' value='1'
<?php if($record['betaald'] == 1){ ?>
checked="checked"
<?php } ?>
/>
</td>
</tr>
<?php } ?>
</table>
Try this
<?php
$sql = "SELECT * FROM registered ORDER BY datum";
$myData= mysql_query($sql) ;
?>
<table width="1100" border="1">
<tr>
<th style="text-align:center; padding:0 10px">naam</th>
<th style="text-align:center; padding:0 10px">betaald</b></th>
</tr>
<?php
while($record = mysql_fetch_array($myData))
{
?>
<tr>
<td> <?php echo $record['naam'] ?></td>
<td> <input type='checkbox' name='betaald' id='betaald' value='1' <?php echo ($record['betaald']==1 ? 'checked' : '')?>> </td>
</tr>
<?php
}
mysql_close($con);
?>
mysql_query($sql) no need to define $con
Note: This extension is deprecated as of PHP 5.5.0, and has been removed as of PHP 7.0.0
<?php
$sql = "SELECT * FROM registered ORDER BY datum";
$myData=mysql_query($sql,$con) ;
?>
<table width="1100" border="1">
<tr>
<th style="text-align:center; padding:0 10px">naam</th>
<th style="text-align:center; padding:0 10px">betaald?</b></th>
</tr>
<?php
while($record = mysql_fetch_array($myData)) {
$betaald = $record['betaald'];
echo "<tr>";
echo "<td>" . $record['naam'] . "</td>";
echo "<td> <input type='checkbox' name='betaald' id='betaald' value='1' ";
echo $betaald==1 ? 'checked' : '';
echo " ></td>";
echo "</tr>";
}
mysql_close($con);
?>
You have assigned $betaald value outside the while loop so there is no value in $betaald.
I have included $betaald inside while loop.
You need several changes in your php and html code. First of all I've some confusion about your code. Let me clear those.
Point 1 [name='betaald']: If you have a name like this you will not get multiple selected value.
Point 2 [id='betaald']: ID must be unique in a page.
Point 3 [value='1']: How will you differ values if all have same value?
so your code should be something like this:
<?php
$sql = "SELECT * FROM registered ORDER BY datum";
$myData=mysql_query($sql,$con) ;
?>
<table width="1100" border="1">
<tr>
<th style="text-align:center; padding:0 10px">naam</th>
<th style="text-align:center; padding:0 10px">betaald?</b></th>
</tr>
<?php
$betaald = $_POST['betaald'];
$i = 1;
while($record = mysql_fetch_array($myData)) {
echo "<tr>";
echo "<td>" . $record['naam'] . "</td>";
echo "<td> <input type='checkbox' name='betaald[]' id='betaald".$i."' value='".$record['betaald']."' ";
if ($record['betaald'] == $betaald)
{
echo "checked";
}
echo " ></td>";
echo "</tr>";
$i++;
}
mysql_close($con);
?>
My PHP and HTML code is used to get data from a MySQL database and display it in a table run through a while loop, however there are random semicolons being output before the table tag starts and the h3 tag ends (seen through inspect element in browser). The number of semicolons outputted matches the number of rows from the SQL query.
echo "<form action='predictions.php' method='POST'>";
echo "<h3>" . $date[0] . "</h3>
<table>
<tr>
<col width='100'>
<col width='50'>
<col width='50'>
<col width='100'>
<col width='70'>
<col width='100'>
<th>Home <br> Team</th>
<th>Home <br> Score</th>
<th>Away <br> Score</th>
<th>Away <br> Team</th>
<th>Match <br> Time </th>
<th>First <br> Scorer </th>
</tr>";
while($row = mysqli_fetch_row($match) and $matchid = mysqli_fetch_array($sqlmatchid)){
if ($date[0] != $row[3]) {
echo "</table>";
echo "<hr>";
$date[0] = $row[3];
echo "<h3>".$date[0]."</h3>
<table>
<tr>
<col width='100'>
<col width='50'>
<col width='50'>
<col width='100'>
<col width='70'>
<col width='100'>
<th>Home <br> Team</th>
<th>Home <br> Score</th>
<th>Away <br> Score</th>
<th>Away <br> Team</th>
<th>Match <br> Time </th>
<th>First <br> Scorer </th>
</tr>";
}
echo "<tr>";
echo "<td>" . $row[0] . "</td>" ?>
<td> <input id='phs' type='text' name=<?php echo "phs".$matchid['MatchID'] ?> size='1' maxlength='1'> </td>
<td> <input id='pas' type='text' name=<?php echo "pas".$matchid['MatchID'] ?> size='1' maxlength='1'> </td>
<?php
$smatchid = $matchid['MatchID']; //match id to find scorer
echo "<td>" . $row[1] . "</td>";
echo "<td>" . $row[2] . "</td>" ?>
<td> <select id="scorer" name=<?php echo "scorer".$matchid['MatchID'] ?>>
<option> </option>
<?php
$result = mysqli_query($con,"SELECT PlayerName
FROM players, matches
WHERE matches.MatchID = '$smatchid' AND (players.TeamID = matches.HTeamID OR players.TeamID = matches.ATeamID)");
while ($row = mysqli_fetch_row($result)){
echo "<option> $row[0] </option>";
}
?>
</select> </td>;
<?php
echo "</tr>";
}
I don't understand why these semicolons are appearing and want to remove them.
The semicolon is coming because you have written </select> </td>;. Semicolon after </td> generating it every time. Remove it from there.