What is wrong with this code? I tried it several times but my DB is not updating after submitting.. I have a table with in the last column check-boxes. The check-boxes show correctly the value from the DB, but I also want the option to update the DB with the check-boxes. So if the value is 1 then the check-box is checked, but I want to be able to uncheck it (or check another that's unchecked) and click on the submit button below to change the value in the DB.
$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"><b>naam</th>
<th style="text-align:center; padding:0 10px">betaald?</b></th>
</tr>
<?php
if(isset($_POST['submit'])){
$betaald = $_POST['betaald'];
mysql_query($con,"UPDATE registered SET betaald='$betaald'");
header("Location: index.php");
} ?>
<?php
while($record = mysql_fetch_array($myData))
{
?>
<tr>
<td> <?php echo $record['naam'] ?></td>
<form method="post" action="<?php echo $PHP_SELF;?>">
<td> <input type='checkbox' name='betaald' id='betaald' value='1' <?php echo ($record['betaald']==1 ? 'checked' : '')?>> </td>
</tr>
<?php
}
mysql_close($con);
?>
</table></p>
<input style="border:1px solid black" name="submit" type="submit" value="Save changes">
</form>
You passed wrong parameters to mysql_query().
The syntax is mysql_query($query); The second parameter is optional
Remove $con from the function.
According to the manual of php.net , the first param is query ,and the second is link identifier(as your $con) which is optional
mixed mysql_query ( string $query [, resource $link_identifier = NULL ] )
Related
The web screenshot shows that the time value is fetched from database column settime, I want to insert my own value into the set time column and update that single row but upon clicking update it doesn't update.
If I were to replace the update query with delete query as shown below it works and delete that particular row. My question is how can I use same method to update that particular column value based on id.
<?php
$id =(isset($_GET['id']) ? $_GET['id'] : null);
if($id!=null) {
$query="delete from activity where id=$id";
$result=mysql_query($query);
}
?>
Web
database
timer.php
<?php include 'header.php'; ?>
<div class="main" >
<table width="900px" cellpadding="5" cellspacing="5">
<tr>
<td style="width:10px"></td>
<td style="background:#F2F2F2; height:400px">
<?php
$settime =(isset($_POST['settime']) ? $_POST['settime'] : null);
$id =(isset($_GET['id']) ? $_GET['id'] : null);
if($id!=null) {
//$settime =(isset($_POST['settime']) ? $_POST['settime'] : null);
$query="update feedtime set settime='$settime' where id=$id";
$result=mysql_query($query);
}
?>
<table width="100%" class="tableStyle">
<tr style="font-weight:bold">
<td>NO.</td>
<td>User</td>
<td>Time</td>
<td>Time Left</td>
<td></td>
</tr>
<?php
$i=0;
$query="select * from feedtime";
$result=mysql_query($query);
while ($row = mysql_fetch_array($result)){
$i+=1;
echo '
<tr style="height:25px">
<td>'.$i.'</td>
<td>'.$row['user'].'</td>
<td><input id="timer" type="text" name="settime" style="width:200px;" value='. $row['settime'].' /></td>
<td>'. $row['timeleft'] .'</td>';echo '
<td align="center"><input type="button" value="Update" style="font-size:10px;width:80px;height:25px;padding:0;margin:0" onclick="location.href=\'timer.php?id='.$row['id'].'\' " /></td>
</tr>';
}
if($i==0)echo '
<tr style="height:25px">
<td colspan="6">Record not found</td>
</tr>'; ?>
</table><br>
<?php echo mysql_error(); ?>
</td>
</tr>
</table>
</div>
<?php include 'footer.php'; ?>
Ignoring the implementation details for a second (like using the MySQL extension), your main problem appears to be submitting (by POST) a single id / settime pair of values.
I would simply make a form per row. Something like this (very simplified)
<?php while($row = fetch_some_data()) : ?>
<tr>
<td>
<input form="form<?= $row['id'] ?>" type="text" name="settime" value="<?= $row['settime'] ?>" />
<td>
<td>
<form id="form<?= $row['id'] ?>" method="post" action="timer.php">
<button type="submit" name="id" value="<?= $row['id'] ?>">UPDATE</button>
</form>
</td>
</tr>
<?php endwhile ?>
Note the form attribute on the <input> and id attribute on the <form> are the same. This lets you tie the input to that form without it being a descendant element, allowing you to include all the required data without bastardising the HTML to get the form to wrap the table-row.
With this, pressing any "UPDATE" button will submit a POST request with data like
id=1&settime=12%3A08%3A00
which you can retrieve in your script via $_POST['id'] and $_POST['settime'].
For example (and using MySQLi)
if (isset($_POST['id'], $_POST['settime'])) {
$stmt = $conn->prepare('UPDATE `feedtime` SET `settime` = ? where `id` = ?');
$stmt->bind_param('si', $_POST['settime'], $_POST['id']);
$stmt->execute();
}
I want to delete multiple rows from my MYSQL database table. I have created this file to select various links and delete them using checkboxes.
This doesn't seem to delete any row. My data is populated in the table. I guess the problem is with my PHP code. Please check the below code and guide me to get out from this...
<html>
<head>
<title>Links Page</title>
</head>
<body>
<h2>Choose and delete selected links.</h2>
<?php
$dbc = mysqli_connect('localhost','root','admin','sample') or die('Error connecting to MySQL server');
$query = "select * from links ORDER BY link_id";
$result = mysqli_query($dbc,$query) or die('Error querying database');
$count=mysqli_num_rows($result);
?>
<table width="400" border="0" cellspacing="1" cellpadding="0">
<tr>
<td>
<form name="form1" method="post" action="">
<table width="400" border="0" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<td bgcolor="#FFFFFF"> </td>
<td colspan="3" bgcolor="#FFFFFF">
<strong>Delete multiple links</strong>
</td>
</tr>
<tr>
<td align="center" bgcolor="#FFFFFF">#</td>
<td align="center" bgcolor="#FFFFFF">
<strong>Link ID</strong>
</td>
<td align="center" bgcolor="#FFFFFF">
<strong>Link Name</strong>
</td>
<td align="center" bgcolor="#FFFFFF">
<strong>Link URL</strong>
</td>
</tr>
<?php
while ($row=mysqli_fetch_array($result)) {
?>
<tr>
<td align="center" bgcolor="#FFFFFF">
<input name="checkbox" type="checkbox" value="
<?php echo $row['link_id']; ?>">
</td>
<td bgcolor="#FFFFFF"> <?php echo $row['link_id']; ?> </td>
<td bgcolor="#FFFFFF"> <?php echo $row['link_name']; ?> </td>
<td bgcolor="#FFFFFF"> <?php echo $row['link_url']; ?> </td>
</tr>
<?php
}
?>
<tr>
<td colspan="4" align="center" bgcolor="#FFFFFF">
<input name="delete" type="submit" value="Delete">
</td>
</tr>
</table>
</form>
</td>
</tr>
</table>
<?php
// Check if delete button active, start this
if(isset($_POST['delete']))
{
$checkbox = $_POST['checkbox'];
for($i=0; $i<count($checkbox); $i++) {
$del_id = $checkbox[$i];
$sql = "DELETE FROM links WHERE link_id='$del_id'";
$result = mysqli_query($sql);
}
// if successful redirect to delete_multiple.php
if($result){
echo '<meta http-equiv="refresh" content="0;URL=view_links.php">';
}
}
mysqli_close($dbc);
?>
</body>
</html>
You should treat it as an array like this,
<input name="checkbox[]" type="checkbox" value="<?php echo $row['link_id']; ?>">
Then only, you can take its count and loop it for deletion.
You also need to pass the database connection to the query.
$result = mysqli_query($dbc, $sql);
Yours did not include it:
$result = mysqli_query($sql);
Use array notation like name="checkbox[]" in your input element. This will give you $_POST['checkbox'] as array. In the query you can utilize it as
$sql = "DELETE FROM links WHERE link_id in ";
$sql.= "('".implode("','",array_values($_POST['checkbox']))."')";
Thats one single query to delete them all.
Note: You need to escape the values passed in $_POST['checkbox'] with mysql_real_escape_string or similar to prevent SQL Injection.
<?php $sql = "SELECT * FROM guest_book";
$res = mysql_query($sql);
if (mysql_num_rows($res)) {
$query = mysql_query("SELECT * FROM guest_book ORDER BY id");
$i=1;
while($row = mysql_fetch_assoc($query)){
?>
<input type="checkbox" name="checkboxstatus[<?php echo $i; ?>]" value="<?php echo $row['id']; ?>" />
<?php $i++; }} ?>
<input type="submit" value="Delete" name="Delete" />
if($_REQUEST['Delete'] != '')
{
if(!empty($_REQUEST['checkboxstatus'])) {
$checked_values = $_REQUEST['checkboxstatus'];
foreach($checked_values as $val) {
$sqldel = "DELETE from guest_book WHERE id = '$val'";
mysql_query($sqldel);
}
}
}
Delete Multiple checkbox using PHP Code
<input type="checkbox" name="chkbox[] value=".$row[0]."/>
<input type="submit" name="delete" value="delete"/>
<?php
if(isset($_POST['delete']))
{
$cnt=array();
$cnt=count($_POST['chkbox']);
for($i=0;$i<$cnt;$i++)
{
$del_id=$_POST['chkbox'][$i];
$query="delete from $tablename where Id=".$del_id;
mysql_query($query);
}
}
Something that sometimes crops up you may/maynot be aware of
Won't always be picked up by by $_POST['delete'] when using IE. Firefox and chrome should work fine though. I use a seperate isntead which solves the problem for IE
As for your not deleting in your code above you appear to be echoing out 2x sets of check boxes both pulling the same data? Is this just a copy + paste mistake or is this actually how your code is?
If its how your code is that'll be the problem as the user could be ticking one checkbox array item but the other one will be unchecked so the php code for delete is getting confused. Either rename the 2nd check box or delete that block of html surely you don't need to display the same list twice ?
$deleted = $_POST['checkbox'];
$sql = "DELETE FROM $tbl_name WHERE id IN (".implode(",", $deleted ) . ")";
I am rather a new addition to this forum. and to coding with PHP so as novice I would like to have all your help.
The problem I face is as follows.
I have a MySQL table 'Announce' with the following fields
id
----------
advert
----------
date
----------
file
----------
approv
----------
to which data gets populated from a page - in which all the columns gets its value except approv. To populate the field there is a new PHP page. The field approv gets the value 'approved' based on the tick of the checkbox in it
The problem I face is that I can't read the values of the text box that display the id and get the corresponding checkbox value so that the particular record gets approved and gets updated to the MySQL table.
The code I wrote is given below
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org
/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Annpouncements | Pending List</title>
<style type="text/css">
.textinput {
height: 20px;
width: 20px;
border-top-width: 0px;
border-right-width: 0px;
border-bottom-width: 0px;
border-left-width: 0px;
border-top-style: none;
border-right-style: none;
border-bottom-style: none;
border-left-style: none;
}
</style>
</head>
<body>
<table width="800" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td> </td>
</tr>
<tr>
<td height="164"><form id="form1" name="form1" method="post" action="">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="11%" height="31" align="center"><label>Id</label></td>
<td width="15%" height="31" align="center"><label>Date</label></td>
<td width="52%" align="center"><label>Title</label></td>
<td width="22%" align="center"><label>Status</label></td>
</tr>
<?php
//Open the table announce from the database and list date in descending order
$result = mysql_query("SELECT * FROM announce ORDER by date DESC" )or
die(mysql_error());
//Define a variable to get the rows of the table
$ann = mysql_fetch_array($result);
//Define a variable to get the no of rows
$num = mysql_num_rows($result);
$i=0;
while($i<$num) {?>
<?php $approv[$i]= mysql_result($result,$i,"approv"); ?>
<tr>
<?php if($approv[$i] !== "approved"){?>
<td height="36" align="center"><input name="id" type="text"
class="textinput" id="id" value="<?php echo mysql_result($result,$i,"id");
?>" /></td>
<?php $ids = mysql_result($result,$i,"id");
//$inp = $_POST["id"][$i];
//echo 'Input value : ' .$inp. '<br/>' ?>
<td height="36" align="center"><label>
<?php echo mysql_result($result,$i,"date"); ?></label></td>
<td align="center"><label><?php echo mysql_result($result,$i,"advert");
?></label></td>
<td align="center"></label><input type="checkbox" name="approv[]" />
<label for="approv"></label></td>
<?php $idan = mysql_query("SELECT * FROM announce WHERE id == $ids"); ?>
<?php
if (isset($_POST['button']))
{
$apprv = $_POST["approv"];
//echo 'id = '.$ids.'<br/>';
$how_many = count($apprv);
//echo 'Row selected' .$how_many. '<br/>';
foreach ($_POST['approv'] as $apprValue)
$txtvalue[] = $_POST[$apprValue];
echo 'txtvalue = ' .$txtvalue. '<br/>';
mysql_query("UPDATE announce SET approv = 'approved'WHERE id ==
$idan ");
}
}
?>
<?php } ?>
</tr>
<?php
$i++;
}
?>
<tr>
<td height="44"> </td>
<td> </td>
<td align="center"> </td>
<td align="center"><input type="submit" name="button" id="button"
value="Submit" /></td>
</tr>
</table>
</form></td>
</tr>
</table></td>
</tr>
</table>
So please help me with getting the correct solution for updating the table with the value 'approved' for only those rows that has been checked.
Looking forward for your valuable help ASAP
A few issues that I found in your queries
This
SELECT * FROM announce WHERE id == $ids
Should be
SELECT * FROM announce WHERE id = '$ids'
And this
UPDATE announce SET approv = 'approved'WHERE id == $idan
Should be
UPDATE announce SET approv = 'approved' WHERE id = '$idan'
Your checkbox doesn't have a value attribute too
<input type="checkbox" name="approv[]" value="<echo your table row id here>" />
Then use
foreach($_POST['approv'] as $apprValue)
{
mysql_query(UPDATE announce SET approv = 'approved' WHERE id = '$apprValue');
}
On a completely side note, please don't use mysql_* functions anymore. They are going to be deprecated soon. Better to go for mysqli or PDO
Ok, so there are a number of issues here, but I'm going to take a stab at the issue being with the lines of code that are generating your checkboxes. Specifically the following bits:
<input name="id" type="text" class="textinput" id="id" value="<?php echo mysql_result($result,$i,"id"); ?>" />
<input type="checkbox" name="approv[]" />
This just isn't a reliable way to create the information that you want, for a number of reasons.
$_POST['id'] will only contain a single value. It will not create a map of ids to approval states that seems to be your intent.
$_POST['approv'] will be a zero-indexed array, leaving you no useful way to correlate a checkbox to an id without keeping a map of id to loop counts. (But if you're going to do that, just use the constructs PHP gives you.)
Ok so, now we know we need to make some changes. First we'll try to get the checkboxes working. But we'll still have the issue of some of your code's structure. Especially since it looks like you don't understand how a request works at all with PHP.
First, we want a way to make sure we know the approval state for each id. That's actually easily remedied. We can just change:
<input type="checkbox" name="approv[]" />
to
<input type="checkbox" name="approv[]" value="<?= $id ?>" />
That way, when you loop over $_POST['approv'], you actually get an id, rather than just an offset. This will allow you to keep the same for loop at the bottom.
BUT THERE ARE STILL ISSUES
There is no reason to be looking at $_POST within your rendering loop (while($i<$num)). Use PHP constructs to your advantage. foreach($result_rows as $row) is much more idiomatic and readable than your code:
//Define a variable to get the rows of the table
$ann = mysql_fetch_array($result);
//Define a variable to get the no of rows
$num = mysql_num_rows($result);
$i=0;
while($i<$num) {?>
... // do work
... // Do something with $_POST. <-- wrong!!!
<? } ?>
Should be something more like:
if (empty($_POST)) {
// Only run the query when we need to display information
$result = mysql_query("SELECT * FROM announce ORDER by date DESC") or die(mysql_error());
//Define a variable to get the rows of the table
$result_rows = mysql_fetch_array($result);
foreach($result_rows as $row) { ?>
... // Display form
<? }
} else {
$success = array();
foreach($_POST['approv'] as $approved_id) {
// Ideally we would combine all of these updates into one statement
$stmt = mysqli_prepare($link, "UPDATE announce SET approv = 'approved' WHERE id = ?i");
mysqli_stmt_bind_params($stmt, $approved_id);
// You then can look over the $success array to see if any failed.
$success[$approved_id] = mysqli_stmt_execute($stmt);
}
}
Rather noobish question but I have tried searching and just cannot find a solution. My problem is I have a table called Off, which stores all of the staffs holidays. However before a staff member may have that day off it has to be authorised. I have a query which gets all of the unauthorised holidays and I display them in a html table. The problem is that I need 2 radio buttons per record. one for authorise and one for deny. The radio buttons are displayed but when going through the records only one of the radio buttons is selectable. Is it possible to use radio buttons in this way?
<?php
$path = $_SERVER['DOCUMENT_ROOT'];
$path .= "/Apollo/dbc.php";
include_once($path);
$rs_results = mysql_query("SELECT * FROM off WHERE IsItAuthorised='0' and isitsick='0' ORDER BY DayOff");
?>
<html>
<head>
<title>Administration Main Page</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<?php
$limit = count($OffID);
if (isset($_POST['submit'])) {
//Assign each array to a variable
$id = $_POST['OffID'];
$answer = $_POST['radio'];
$limit = count($OffID);
$values = array(); // initialize an empty array to hold the values
for($k=0;$k<$limit;$k++){
$msg[] = "$limit New KPI's Added";
$query = "UPDATE Off SET IsItAuthorised = '{$answer[$k]}' WHERE OffID = '{$OffID[$k]}'";
}
$Event = "INSERT INTO events (UserName, Event ) VALUES ('$_SESSION[user_name]', 'Entered New KPI' )";
if (!mysql_query($query,$link)){
die('Error: ' . mysql_error());
} else {
mysql_query($Event);
echo "<div class=\"msg\">" . $msg[0] . "</div>";
}
}
?>
</head>
<body>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="14%" valign="top"><?php
?>
</td>
<td width="74%" valign="top" style="padding: 10px;">
<p><?php
if(!empty($msg)) {
echo $msg[0];
}
?></p>
<p>
<?php
$cond = '';
$sql = "select * from off ";
$rs_total = mysql_query($sql) or die(mysql_error());
$total = mysql_num_rows($rs_total);
?>
<p>
<form name "searchform" action="/Apollo/Admin/HolidayRequests" method="post">
<table width="100%" border="0" align="center" cellpadding="2" cellspacing="0">
<tr class="mytables">
<td width="4%"><font color="white"><strong>ID</font></strong></td>
<td width="4%"> <font color="white"><strong>Staff Member</font></strong></td>
<td width="10%"><font color="white"><strong>Day Off</font></strong></div></td>
<td width="10%"><font color="white"><strong>Is It Authorized</font></strong></div></td>
<td width="15%"> </td>
</tr>
<tr>
<td> </td>
<td width="10%"> </td>
<td width="17%"><div align="center"></div></td>
<td> </td>
</tr>
<?php while ($rrows = mysql_fetch_array($rs_results)) {?>
<tr>
<td><input type="" name="id[]" id="id[]" size="4" value="<?php echo $rrows['OffID'];?>" /></td>
<td><?php echo $rrows['StaffMember']; ?></td>
<td><?php echo date('d/m/Y', strtotime($rrows['DayOff']));?></div></td>
<td> <span id="approve<?php echo $rrows['id']; ?>">
<?php if(!$rrows['IsItAuthorised']) { echo "Pending"; } else {echo "Authorized"; }?>
</span> </td>
<td>
<input type="radio" name="radio[0]" id="radio[0]" value="1" />Approve
<input type="radio" name="radio[1]" id="radio[1]" value="0" />Deny
</td>
</tr>
<?php } ?>
</table>
<input name="submit" type="submit" id="submit" value="Submit">
</form>
</p>
<?php
?>
<p> </p>
<p> </p>
<p> </p>
<p> </p></td>
<td width="12%"> </td>
</tr>
</table>
</body>
</html>
Your problem is to do with your use of the "name" attribute - this attribute is used in a special way on radio buttons.
When you click on a radio button, all the other radio buttons with the same name are deselected - in your case, you will have half of the radio buttons on the page in one group and half in another, which would probably explain why you can only select one. I'd imagine you can actually select two at the same time, if you click on the right radio buttons.
To fix this you'd need to have some kind of count for the while loop, ie:
$resultNumber = 0;
while ($rrows = mysql_fetch_array($rs_results)) {
Then you'd need to use this number in the name (and also id) of the radio buttons -
<input type="radio" name="radio<?php echo $resultNumber; ?>" id="radio<?php echo $resultNumber; ?>" value="1" />
Then simply increment the $resultNumber at the end of each iteration -
<?php
$resultNumber++;
}
?>
Alternatively, you could use the primary key of the row from the database table you're querying to distinguish groups, but not knowing the table structure I couldn't give sample code for that.
Further reading on radio buttons (also a source for the name attribute problem) :
http://www.echoecho.com/htmlforms10.htm
Instead of radio buttons, I used checkboxes, which I looped through. Each checkbox set a value to a different column. Should have been obvious to me to begin with.
my current problem is :
I have a HTML table created "dynamically" according to how many rows brings back a mysql_query. The first column gets tha data from the query and the second column have a text field (see below):
<?php
$selApart = "SELECT idAPARTMENT FROM BUILDING, APARTMENT WHERE APARTMENT.BUILDING_ID = BUILDING.idBUILDING AND idBUILDING = '$building'";
$res = mysql_query($selApart) or die("Could not execute query.");
?>
<table width="244" border="0" cellspacing="0" id="hours_table">
<tr>
<td width="121">APARTMENT</td>
<td width="119">HOURS</td>
</tr>
<?php
$rcnt = 0;
while($r = mysql_fetch_array($res)){
$a = $r['idAPARTMENT'];
$rcnt++;
$rid = 'row'.$rcnt;
?>
<tr>
<td>'<?php echo $a?>'</td>
<td id='<?php echo $rid?>'><input type="text" name="hours" id="hours" value="0"/></td>
</tr>
<?php } ?>
<input type="submit" name="complete" id="complete" align="middle" value="INSERT"/>
After my table is "ready", I want to fill in my text fields and insert these values in an sql table. What I don't know is how I can get the value of each column through the id I set, sth like
if(isset($_POST['complete'])){
for($i=0; $i<$rcnt; $i++){
//INSERT INTO APARTMENT (idAPARTMENT, HOURS) VALUES ($a, **table.row.id**)
}
}
Can someone help? Is this possible to be done?
Thanks in advance!
He, thing you have to do is add $rid as name to text box, then just submit form and you will have them in $_POST["row"+$rid];
You can loop through every $_POST and if variable starts with row + num save it in db
foreach($_POST as $key => $value)
//if $key starts with row execute your db save
I hope this helps
Put that table into a form with method=POST and when submitting you'll find all input's in the $_POST array by name.
<?php
print_r($_POST);//this will just show you the contents of the array, you play with it later on
$selApart = "SELECT idAPARTMENT FROM BUILDING, APARTMENT WHERE APARTMENT.BUILDING_ID = BUILDING.idBUILDING AND idBUILDING = '$building'";
$res = mysql_query($selApart) or die("Could not execute query.");
?>
<form action="" method="POST"><!-- table must be included in a form with action pointing the script location, "" means itself -->
<table width="244" border="0" cellspacing="0" id="hours_table">
<tr>
<td width="121">APARTMENT</td>
<td width="119">HOURS</td>
</tr>
<?php
$rcnt = 0;
while($r = mysql_fetch_array($res)){
$a = $r['idAPARTMENT'];
$rcnt++;
$rid = 'row'.$rcnt;
?>
<tr>
<td>'<?php echo $a?>'</td>
<td id='<?php echo $rid?>'><input type="text" name="hours<?= $a ?>" id="hours" value="0"/></td><!-- name="hourse<?= $a ?>" each name must be unique, that's why you include the ID from your table. It's not a good idea to put a counter, use actual data from the table. -->
</tr>
<?php } ?>
</table>
<input type="submit" name="complete" id="complete" align="middle" value="INSERT"/>
</form>
The post "get data from dynamically created html table for certain columns" was very useful. It helped me a lot, but needs a little change:
<?php
//database connectivity
mysql_connect ("localhost","root","","sis")or die("cannot connect");
mysql_select_db("sis")or die("cannot select DB");
//query to fetch data
$sql1="select * from student";
$result1= mysql_query($sql1);
// forming table to view data
if($result1){
echo "<table cellspacing='1' cellpadding='5'>
<th width='30%'>Roll_No </th>
<th width='40%'>Name </th>
<th width='30%'>Sem & Sec </th>";
while($row=mysql_fetch_array($result1)){
$Roll_No=$row['Roll_No'];
$Name=$row['Name'];
$Sem_Sec=$row['Sem_Sec'];
echo"<tr>
<td>$Roll_No</td>
<td>$Name</td>
<td>$Sem_Sec</td>
</tr>";
}
?>