Updating a single value in a reord not working with a button?
I have a database of a checklist, and am displaying the database in tables, one table for items on the list that are complete and one for those that arent. I have a button on each row of the uncomplete table that when I click I want it to update the database and send the record to the completed table.
<div class="table_undone">
<!--Display undone checklist items-->
<h2>STILL TO DO</h2>
<?php
$sql = "SELECT * FROM checklist WHERE done = '' ORDER BY id";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
//display the header of the table
echo "<table>
<tr>
<th>ITEM</th>
<th>DUE DATE</th>
<th></th>
<th></th>
</tr>";
while ($row = $result->fetch_assoc()) {
//display the contents of the table
echo "<tr>
<td>".$row['item']."</td>
<td>".$row['due_date']."</td>
<td>
<form id='complete_item' name='complete_item' action='index.php' method='get'>
<button class='button' type='button' name='complete' value=".row['id'].">COMPLETE</button>
</form>
</tr>";
}
echo "</table>";
} else {
echo "0 RESULTS";
}
?>
</div>
I have this to display the table.
<?php
//once an item is complete send it to the completed table using the complete button
$id=$_POST['id'];
$item=$_POST['item'];
$due_date=$_POST['due_date'];
$done=$_POST['done'];
if(isset($_POST['complete'])) {
$sql = "UPDATE checklist SET done = 'y' WHERE id=$id";
$result = mysqli_query($conn,$sql);
if ($sql) {
echo "Success in updating the record!";
} else {
echo "Failure in updating the record!";
}
}
?>
and this to update the record, changing the done value to "y", which then would dsplay it in the correct table, but this isnt working?
Any help would be appreciated!
php html sql
add a comment |
I have a database of a checklist, and am displaying the database in tables, one table for items on the list that are complete and one for those that arent. I have a button on each row of the uncomplete table that when I click I want it to update the database and send the record to the completed table.
<div class="table_undone">
<!--Display undone checklist items-->
<h2>STILL TO DO</h2>
<?php
$sql = "SELECT * FROM checklist WHERE done = '' ORDER BY id";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
//display the header of the table
echo "<table>
<tr>
<th>ITEM</th>
<th>DUE DATE</th>
<th></th>
<th></th>
</tr>";
while ($row = $result->fetch_assoc()) {
//display the contents of the table
echo "<tr>
<td>".$row['item']."</td>
<td>".$row['due_date']."</td>
<td>
<form id='complete_item' name='complete_item' action='index.php' method='get'>
<button class='button' type='button' name='complete' value=".row['id'].">COMPLETE</button>
</form>
</tr>";
}
echo "</table>";
} else {
echo "0 RESULTS";
}
?>
</div>
I have this to display the table.
<?php
//once an item is complete send it to the completed table using the complete button
$id=$_POST['id'];
$item=$_POST['item'];
$due_date=$_POST['due_date'];
$done=$_POST['done'];
if(isset($_POST['complete'])) {
$sql = "UPDATE checklist SET done = 'y' WHERE id=$id";
$result = mysqli_query($conn,$sql);
if ($sql) {
echo "Success in updating the record!";
} else {
echo "Failure in updating the record!";
}
}
?>
and this to update the record, changing the done value to "y", which then would dsplay it in the correct table, but this isnt working?
Any help would be appreciated!
php html sql
What part is not working? The update command works fine?
– Banujan Balendrakumar
Nov 28 '18 at 18:08
When i press the button nothing happens for some reason?
– oliver thomas
Nov 28 '18 at 18:08
add a comment |
I have a database of a checklist, and am displaying the database in tables, one table for items on the list that are complete and one for those that arent. I have a button on each row of the uncomplete table that when I click I want it to update the database and send the record to the completed table.
<div class="table_undone">
<!--Display undone checklist items-->
<h2>STILL TO DO</h2>
<?php
$sql = "SELECT * FROM checklist WHERE done = '' ORDER BY id";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
//display the header of the table
echo "<table>
<tr>
<th>ITEM</th>
<th>DUE DATE</th>
<th></th>
<th></th>
</tr>";
while ($row = $result->fetch_assoc()) {
//display the contents of the table
echo "<tr>
<td>".$row['item']."</td>
<td>".$row['due_date']."</td>
<td>
<form id='complete_item' name='complete_item' action='index.php' method='get'>
<button class='button' type='button' name='complete' value=".row['id'].">COMPLETE</button>
</form>
</tr>";
}
echo "</table>";
} else {
echo "0 RESULTS";
}
?>
</div>
I have this to display the table.
<?php
//once an item is complete send it to the completed table using the complete button
$id=$_POST['id'];
$item=$_POST['item'];
$due_date=$_POST['due_date'];
$done=$_POST['done'];
if(isset($_POST['complete'])) {
$sql = "UPDATE checklist SET done = 'y' WHERE id=$id";
$result = mysqli_query($conn,$sql);
if ($sql) {
echo "Success in updating the record!";
} else {
echo "Failure in updating the record!";
}
}
?>
and this to update the record, changing the done value to "y", which then would dsplay it in the correct table, but this isnt working?
Any help would be appreciated!
php html sql
I have a database of a checklist, and am displaying the database in tables, one table for items on the list that are complete and one for those that arent. I have a button on each row of the uncomplete table that when I click I want it to update the database and send the record to the completed table.
<div class="table_undone">
<!--Display undone checklist items-->
<h2>STILL TO DO</h2>
<?php
$sql = "SELECT * FROM checklist WHERE done = '' ORDER BY id";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
//display the header of the table
echo "<table>
<tr>
<th>ITEM</th>
<th>DUE DATE</th>
<th></th>
<th></th>
</tr>";
while ($row = $result->fetch_assoc()) {
//display the contents of the table
echo "<tr>
<td>".$row['item']."</td>
<td>".$row['due_date']."</td>
<td>
<form id='complete_item' name='complete_item' action='index.php' method='get'>
<button class='button' type='button' name='complete' value=".row['id'].">COMPLETE</button>
</form>
</tr>";
}
echo "</table>";
} else {
echo "0 RESULTS";
}
?>
</div>
I have this to display the table.
<?php
//once an item is complete send it to the completed table using the complete button
$id=$_POST['id'];
$item=$_POST['item'];
$due_date=$_POST['due_date'];
$done=$_POST['done'];
if(isset($_POST['complete'])) {
$sql = "UPDATE checklist SET done = 'y' WHERE id=$id";
$result = mysqli_query($conn,$sql);
if ($sql) {
echo "Success in updating the record!";
} else {
echo "Failure in updating the record!";
}
}
?>
and this to update the record, changing the done value to "y", which then would dsplay it in the correct table, but this isnt working?
Any help would be appreciated!
php html sql
php html sql
asked Nov 28 '18 at 18:05
oliver thomasoliver thomas
197
197
What part is not working? The update command works fine?
– Banujan Balendrakumar
Nov 28 '18 at 18:08
When i press the button nothing happens for some reason?
– oliver thomas
Nov 28 '18 at 18:08
add a comment |
What part is not working? The update command works fine?
– Banujan Balendrakumar
Nov 28 '18 at 18:08
When i press the button nothing happens for some reason?
– oliver thomas
Nov 28 '18 at 18:08
What part is not working? The update command works fine?
– Banujan Balendrakumar
Nov 28 '18 at 18:08
What part is not working? The update command works fine?
– Banujan Balendrakumar
Nov 28 '18 at 18:08
When i press the button nothing happens for some reason?
– oliver thomas
Nov 28 '18 at 18:08
When i press the button nothing happens for some reason?
– oliver thomas
Nov 28 '18 at 18:08
add a comment |
1 Answer
1
active
oldest
votes
change viewing code to following... Bcoz button no need.
while ($row = $result->fetch_assoc()) {
//display the contents of the table
echo "<tr>
<td>".$row['item']."</td>
<td>".$row['due_date']."</td>
<td><a href='update.php?id=".$row['id']."'>complete</a></td>
</tr>";
}
And your update.php should be like (Your same code But small changes),
<?php
//once an item is complete send it to the completed table using the complete button
// make sure the $conn is exist
$id=$_GET['id'];
$sql = "UPDATE checklist SET done = 'y' WHERE id='$id'";
$result = mysqli_query($conn,$sql);
if ($sql) {
echo "Success in updating the record!";
} else {
echo "Failure in updating the record!";
}
}
?>
thank you! that worked, is there anyway for it to automatically go back to the page again after?
– oliver thomas
Nov 28 '18 at 18:19
put this line at the point where you want to redirect,header("location: yourpage.php");
– Banujan Balendrakumar
Nov 28 '18 at 18:21
@oliverthomas Good luck! Cheers... Mark this answer if this really solved your problem.
– Banujan Balendrakumar
Nov 28 '18 at 18:33
Thank yoiu very much for the help this is brilliant!
– oliver thomas
Nov 28 '18 at 18:44
@oliverthomas You are always welcome.
– Banujan Balendrakumar
Nov 28 '18 at 18:50
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53525531%2fupdating-a-single-value-in-a-reord-not-working-with-a-button%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
change viewing code to following... Bcoz button no need.
while ($row = $result->fetch_assoc()) {
//display the contents of the table
echo "<tr>
<td>".$row['item']."</td>
<td>".$row['due_date']."</td>
<td><a href='update.php?id=".$row['id']."'>complete</a></td>
</tr>";
}
And your update.php should be like (Your same code But small changes),
<?php
//once an item is complete send it to the completed table using the complete button
// make sure the $conn is exist
$id=$_GET['id'];
$sql = "UPDATE checklist SET done = 'y' WHERE id='$id'";
$result = mysqli_query($conn,$sql);
if ($sql) {
echo "Success in updating the record!";
} else {
echo "Failure in updating the record!";
}
}
?>
thank you! that worked, is there anyway for it to automatically go back to the page again after?
– oliver thomas
Nov 28 '18 at 18:19
put this line at the point where you want to redirect,header("location: yourpage.php");
– Banujan Balendrakumar
Nov 28 '18 at 18:21
@oliverthomas Good luck! Cheers... Mark this answer if this really solved your problem.
– Banujan Balendrakumar
Nov 28 '18 at 18:33
Thank yoiu very much for the help this is brilliant!
– oliver thomas
Nov 28 '18 at 18:44
@oliverthomas You are always welcome.
– Banujan Balendrakumar
Nov 28 '18 at 18:50
add a comment |
change viewing code to following... Bcoz button no need.
while ($row = $result->fetch_assoc()) {
//display the contents of the table
echo "<tr>
<td>".$row['item']."</td>
<td>".$row['due_date']."</td>
<td><a href='update.php?id=".$row['id']."'>complete</a></td>
</tr>";
}
And your update.php should be like (Your same code But small changes),
<?php
//once an item is complete send it to the completed table using the complete button
// make sure the $conn is exist
$id=$_GET['id'];
$sql = "UPDATE checklist SET done = 'y' WHERE id='$id'";
$result = mysqli_query($conn,$sql);
if ($sql) {
echo "Success in updating the record!";
} else {
echo "Failure in updating the record!";
}
}
?>
thank you! that worked, is there anyway for it to automatically go back to the page again after?
– oliver thomas
Nov 28 '18 at 18:19
put this line at the point where you want to redirect,header("location: yourpage.php");
– Banujan Balendrakumar
Nov 28 '18 at 18:21
@oliverthomas Good luck! Cheers... Mark this answer if this really solved your problem.
– Banujan Balendrakumar
Nov 28 '18 at 18:33
Thank yoiu very much for the help this is brilliant!
– oliver thomas
Nov 28 '18 at 18:44
@oliverthomas You are always welcome.
– Banujan Balendrakumar
Nov 28 '18 at 18:50
add a comment |
change viewing code to following... Bcoz button no need.
while ($row = $result->fetch_assoc()) {
//display the contents of the table
echo "<tr>
<td>".$row['item']."</td>
<td>".$row['due_date']."</td>
<td><a href='update.php?id=".$row['id']."'>complete</a></td>
</tr>";
}
And your update.php should be like (Your same code But small changes),
<?php
//once an item is complete send it to the completed table using the complete button
// make sure the $conn is exist
$id=$_GET['id'];
$sql = "UPDATE checklist SET done = 'y' WHERE id='$id'";
$result = mysqli_query($conn,$sql);
if ($sql) {
echo "Success in updating the record!";
} else {
echo "Failure in updating the record!";
}
}
?>
change viewing code to following... Bcoz button no need.
while ($row = $result->fetch_assoc()) {
//display the contents of the table
echo "<tr>
<td>".$row['item']."</td>
<td>".$row['due_date']."</td>
<td><a href='update.php?id=".$row['id']."'>complete</a></td>
</tr>";
}
And your update.php should be like (Your same code But small changes),
<?php
//once an item is complete send it to the completed table using the complete button
// make sure the $conn is exist
$id=$_GET['id'];
$sql = "UPDATE checklist SET done = 'y' WHERE id='$id'";
$result = mysqli_query($conn,$sql);
if ($sql) {
echo "Success in updating the record!";
} else {
echo "Failure in updating the record!";
}
}
?>
answered Nov 28 '18 at 18:13
Banujan BalendrakumarBanujan Balendrakumar
9921213
9921213
thank you! that worked, is there anyway for it to automatically go back to the page again after?
– oliver thomas
Nov 28 '18 at 18:19
put this line at the point where you want to redirect,header("location: yourpage.php");
– Banujan Balendrakumar
Nov 28 '18 at 18:21
@oliverthomas Good luck! Cheers... Mark this answer if this really solved your problem.
– Banujan Balendrakumar
Nov 28 '18 at 18:33
Thank yoiu very much for the help this is brilliant!
– oliver thomas
Nov 28 '18 at 18:44
@oliverthomas You are always welcome.
– Banujan Balendrakumar
Nov 28 '18 at 18:50
add a comment |
thank you! that worked, is there anyway for it to automatically go back to the page again after?
– oliver thomas
Nov 28 '18 at 18:19
put this line at the point where you want to redirect,header("location: yourpage.php");
– Banujan Balendrakumar
Nov 28 '18 at 18:21
@oliverthomas Good luck! Cheers... Mark this answer if this really solved your problem.
– Banujan Balendrakumar
Nov 28 '18 at 18:33
Thank yoiu very much for the help this is brilliant!
– oliver thomas
Nov 28 '18 at 18:44
@oliverthomas You are always welcome.
– Banujan Balendrakumar
Nov 28 '18 at 18:50
thank you! that worked, is there anyway for it to automatically go back to the page again after?
– oliver thomas
Nov 28 '18 at 18:19
thank you! that worked, is there anyway for it to automatically go back to the page again after?
– oliver thomas
Nov 28 '18 at 18:19
put this line at the point where you want to redirect,
header("location: yourpage.php");
– Banujan Balendrakumar
Nov 28 '18 at 18:21
put this line at the point where you want to redirect,
header("location: yourpage.php");
– Banujan Balendrakumar
Nov 28 '18 at 18:21
@oliverthomas Good luck! Cheers... Mark this answer if this really solved your problem.
– Banujan Balendrakumar
Nov 28 '18 at 18:33
@oliverthomas Good luck! Cheers... Mark this answer if this really solved your problem.
– Banujan Balendrakumar
Nov 28 '18 at 18:33
Thank yoiu very much for the help this is brilliant!
– oliver thomas
Nov 28 '18 at 18:44
Thank yoiu very much for the help this is brilliant!
– oliver thomas
Nov 28 '18 at 18:44
@oliverthomas You are always welcome.
– Banujan Balendrakumar
Nov 28 '18 at 18:50
@oliverthomas You are always welcome.
– Banujan Balendrakumar
Nov 28 '18 at 18:50
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53525531%2fupdating-a-single-value-in-a-reord-not-working-with-a-button%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
What part is not working? The update command works fine?
– Banujan Balendrakumar
Nov 28 '18 at 18:08
When i press the button nothing happens for some reason?
– oliver thomas
Nov 28 '18 at 18:08