Jump to content

Static Pages - Carrying Variable Over to Update, Delete, and Insert SQL Data


Recommended Posts

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!

 

:D

 

<?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>

<?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>";
}?>

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...

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

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>

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.