CloudSex13 Posted December 5, 2008 Share Posted December 5, 2008 i've been developing php for over 5 years now, but i think lack of sleep got the best of me. what i'm trying to do is: 1.) pull 'tasks' from a database. 2.) create separate edit, mark as complete, and delete static links to do those whatever of those to that corresponding task. i'm stuck on numero 2. i've made the pages work fine, but under the complete section, it just won't update the sql database. all database info is correct. i'm messing something up in the code, i know it. my mind's gonna explode :-X anyway, here's the code below. any help is GREATLY appreciated! THANK YOU IF SO! <?php include('connect.php'); include('funcs.php'); $tasks = mysql_query("SELECT * FROM Tasks WHERE AccountID='".$AccountID."' ORDER BY Priority DESC"); $alltasks = 1; while ($gettasks = mysql_fetch_array($tasks)) { $TaskID = $gettasks['TaskID']; $TaskAccountID = $gettasks['AccountID']; $Task = $gettasks['Task']; $Created = $gettasks['Created']; $Deadline = $gettasks['Deadline']; $Priority = $gettasks['Priority']; $Status = $gettasks['Status']; if ($Deadline == 0) { $Deadline = "none."; } else { $Deadline = "".prettyDate($Deadline).""; } if ($Priority == 1) { $Priority = "high."; } elseif ($Priority == 2) { $Priority = "medium."; } elseif ($Priority == 3) { $Priority = "low."; } else { $Priority = "unknown."; } if ($alltasks == 1) { $displaytasks .= " <table align=center width=100% class=t1> <tr> <td align=left width=100%> ".$Task." </td> </tr> <tr> <td align=left width=100%> <span class=small> created: ".prettyDate($Created)." | deadline: ".$Deadline." | priority: ".$Priority." </span> </td> </tr> <tr> <td align=left width=100%> <span class=small> <a class=small href=tasks.php?action=edit&taskid=".$TaskID.">edit</a> | <a class=small href=tasks.php?action=complete&taskid=".$TaskID.">complete</a> | <a class=small href=tasks.php?action=delete&taskid=".$TaskID.">delete</a> </span> </td> </tr> </table>"; $alltasks = 2; } else { $displaytasks .= " <table align=center width=100% class=t2> <tr> <td align=left width=100%> ".$Task." </td> </tr> <tr> <td align=left width=100%> <span class=small> created: ".prettyDate($Created)." | deadline: ".$Deadline." | priority: ".$Priority." </span> </td> </tr> <tr> <td align=left width=100%> <span class=small> <a class=small href=tasks.php?action=edit&taskid=".$TaskID.">edit</a> | <a class=small href=tasks.php?action=complete&taskid=".$TaskID.">complete</a> | <a class=small href=tasks.php?action=delete&taskid=".$TaskID.">delete</a> </span> </td> </tr> </table>"; $alltasks = 1; } } function edit() { echo "under construction.<br><br>"; } function complete() { mysql_query("UPDATE Tasks SET Status='3' WHERE TaskID='".$TaskID."' LIMIT 1"); echo "this task is now complete.<br><br>"; } function delete() { echo "under construction.<br><br>"; } ?> <table width=100% align=center cellpadding=4> <tr> <td width=100% align=center valign=top> <span class=title> tasks </span> </td> </tr> <tr> <td width=100% align=center valign=top> <?php if (isset($_GET['action']) && isset($_GET['taskid'])) { $action = ($_GET['action']); if ($action == "edit") { edit(); } elseif ($action == "complete") { complete(); } elseif ($action == "delete") { delete(); } else { echo " <span class=error> that category does not exist. </span> <br><br>"; } } ?> <?php echo($displaytasks); ?> </td> </tr> </table> Quote Link to comment https://forums.phpfreaks.com/topic/135602-static-pages-carrying-variable-over-to-update-delete-and-insert-sql-data/ Share on other sites More sharing options...
CloudSex13 Posted December 5, 2008 Author Share Posted December 5, 2008 i changed around different variables in the WHERE clause under the complete section, but that still didn't update. i must be doing something stupid. heh. Quote Link to comment https://forums.phpfreaks.com/topic/135602-static-pages-carrying-variable-over-to-update-delete-and-insert-sql-data/#findComment-706465 Share on other sites More sharing options...
darkfreaks Posted December 5, 2008 Share Posted December 5, 2008 <?php function complete() { mysql_query("UPDATE Tasks SET Status='3' WHERE TaskID='".$TaskID."' LIMIT 1")or die("can not update database:".mysql_error()); echo "this task is now complete.<br><br>"; }?> Quote Link to comment https://forums.phpfreaks.com/topic/135602-static-pages-carrying-variable-over-to-update-delete-and-insert-sql-data/#findComment-706470 Share on other sites More sharing options...
.josh Posted December 5, 2008 Share Posted December 5, 2008 My vote is that you didn't pass $TaskID to your function. Quote Link to comment https://forums.phpfreaks.com/topic/135602-static-pages-carrying-variable-over-to-update-delete-and-insert-sql-data/#findComment-706471 Share on other sites More sharing options...
CloudSex13 Posted December 5, 2008 Author Share Posted December 5, 2008 ay darkfreaks, thanks for the response. there's no errors in my code. i'm just forgetting something - i just don't know what. x.x --------- hi crayon violent, thanks for the reply. if by you mean doing this: function complete($TaskID) { mysql_query("UPDATE Tasks SET Status='3' WHERE TaskID='".$TaskID."' LIMIT 1"); echo "this tasks is now complete.<br><br>"; } still no luck - tried that... Quote Link to comment https://forums.phpfreaks.com/topic/135602-static-pages-carrying-variable-over-to-update-delete-and-insert-sql-data/#findComment-706475 Share on other sites More sharing options...
.josh Posted December 5, 2008 Share Posted December 5, 2008 Right. So what about passing it to the function when you call it, as well. Quote Link to comment https://forums.phpfreaks.com/topic/135602-static-pages-carrying-variable-over-to-update-delete-and-insert-sql-data/#findComment-706478 Share on other sites More sharing options...
CloudSex13 Posted December 5, 2008 Author Share Posted December 5, 2008 isn't that what i just did...? Quote Link to comment https://forums.phpfreaks.com/topic/135602-static-pages-carrying-variable-over-to-update-delete-and-insert-sql-data/#findComment-706483 Share on other sites More sharing options...
.josh Posted December 5, 2008 Share Posted December 5, 2008 function perplexed($var) { // <-- function needs an argument passed echo $var; } perplexed("I don't understand how someone with 5yrs xp doesn't know this..."); // <-- need to pass argument to function Quote Link to comment https://forums.phpfreaks.com/topic/135602-static-pages-carrying-variable-over-to-update-delete-and-insert-sql-data/#findComment-706485 Share on other sites More sharing options...
CloudSex13 Posted December 5, 2008 Author Share Posted December 5, 2008 ohhh, i got you. i'm self-taught man, take it easy. and exhausted, hahaha. thank youuu. Quote Link to comment https://forums.phpfreaks.com/topic/135602-static-pages-carrying-variable-over-to-update-delete-and-insert-sql-data/#findComment-706487 Share on other sites More sharing options...
CloudSex13 Posted December 5, 2008 Author Share Posted December 5, 2008 i ran into another major problem when doing this. let's say there are 3 tasks in the database. the php code outputs all 3 on the page. you click "complete" for taskid=1, and for some reason, the database is updated for taskid=2. the same happens with taskid=3. there's no errors, i think i'm missing something stupid again. honestly, i'm completely* oblivious for this one. to me, everything seems perfectly fine. i guess i'm just blind. and extremely tired now. blahh. thank you for any help if so. <?php include('connect.php'); include('funcs.php'); $tasks = mysql_query("SELECT * FROM Tasks WHERE AccountID='".$AccountID."' ORDER BY Priority DESC"); $alltasks = 1; while ($gettasks = mysql_fetch_array($tasks)) { $TaskID = $gettasks['TaskID']; $TaskAccountID = $gettasks['AccountID']; $Task = $gettasks['Task']; $Created = $gettasks['Created']; $Deadline = $gettasks['Deadline']; $Priority = $gettasks['Priority']; $Status = $gettasks['Status']; if ($Deadline == 0) { $Deadline = "none."; } else { $Deadline = "".prettyDate($Deadline).""; } if ($Priority == 1) { $Priority = "high."; } elseif ($Priority == 2) { $Priority = "medium."; } elseif ($Priority == 3) { $Priority = "low."; } else { $Priority = "unknown."; } if ($alltasks == 1) { $displaytasks .= " <table align=center width=100% class=t1> <tr> <td align=left width=100%> ".$Task." </td> </tr> <tr> <td align=left width=100%> <span class=small> created: ".prettyDate($Created)." | deadline: ".$Deadline." | priority: ".$Priority." </span> </td> </tr> <tr> <td align=left width=100%> <span class=small> <a class=small href=tasks.php?action=edit&taskid=".$TaskID.">edit</a> | <a class=small href=tasks.php?action=complete&taskid=".$TaskID.">complete</a> | <a class=small href=tasks.php?action=delete&taskid=".$TaskID.">delete</a> </span> </td> </tr> </table>"; $alltasks = 2; } else { $displaytasks .= " <table align=center width=100% class=t2> <tr> <td align=left width=100%> ".$Task." </td> </tr> <tr> <td align=left width=100%> <span class=small> created: ".prettyDate($Created)." | deadline: ".$Deadline." | priority: ".$Priority." </span> </td> </tr> <tr> <td align=left width=100%> <span class=small> <a class=small href=tasks.php?action=edit&taskid=".$TaskID.">edit</a> | <a class=small href=tasks.php?action=complete&taskid=".$TaskID.">complete</a> | <a class=small href=tasks.php?action=delete&taskid=".$TaskID.">delete</a> </span> </td> </tr> </table>"; $alltasks = 1; } } function edit() { echo "under construction.<br><br>"; } function complete($TaskID) { mysql_query("UPDATE Tasks SET Status='2' WHERE TaskID='".$TaskID."' LIMIT 1"); echo "this task is now complete.<br><br>"; } function delete() { echo "under construction.<br><br>"; } ?> <table width=100% align=center cellpadding=4> <tr> <td width=100% align=center valign=top> <span class=title> tasks </span> </td> </tr> <tr> <td width=100% align=center valign=top> <?php if (isset($_GET['action']) && isset($_GET['taskid'])) { $action = ($_GET['action']); if ($action == "edit") { edit(); } elseif ($action == "complete") { complete($TaskID); } elseif ($action == "delete") { delete(); } else { echo " <span class=error> that category does not exist. </span> <br><br>"; } } ?> <?php echo($displaytasks); ?> </td> </tr> </table> Quote Link to comment https://forums.phpfreaks.com/topic/135602-static-pages-carrying-variable-over-to-update-delete-and-insert-sql-data/#findComment-706534 Share on other sites More sharing options...
.josh Posted December 5, 2008 Share Posted December 5, 2008 Okay your most immediate reason is that you're checking to see if $_GET['taskid'] exists but then pass $TaskID to your function, instead of $_GET['taskid']. So you're passing to your function whatever $TaskID happened to be last, which is not the id that was passed through the url. Quote Link to comment https://forums.phpfreaks.com/topic/135602-static-pages-carrying-variable-over-to-update-delete-and-insert-sql-data/#findComment-706551 Share on other sites More sharing options...
CloudSex13 Posted December 5, 2008 Author Share Posted December 5, 2008 oh man. that would make sense. i'm all rested now, thank you very much again. :] Quote Link to comment https://forums.phpfreaks.com/topic/135602-static-pages-carrying-variable-over-to-update-delete-and-insert-sql-data/#findComment-706796 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.