Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with php form and database

Status
Not open for further replies.

wysiwygGER01

Programmer
Feb 18, 2009
188
AU
Hi,

The code below returns a list of tasks. Each task has an ID.
I'd like to be able to modify each task by clicking on 'modify'

So far I'd just like it to show me the new query if I click on modify but I can't get it to jump into the IF block.
Could anyone here please advise what I'm missing or point me to a working example so I can look for myself?

Thanks in advance.


Code:
<table>
<tbody>
<?php

$action = $_GET['action'];

IF($action == "modify")
    {
	$query_role="SELECT Tasks FROM  jobdescription2 where TaskID = '????'";
	echo "$query_role";
}
ELSE{
	$query_role="SELECT Tasks, TaskID FROM  jobdescription2 where roles = 'Admin'";
}
?>

<form name="form_modify" action="<?php $_SESSION['PHP_SELF']?>">

<?php
$con = odbc_connect( 'database' , 'root', 'test' );

$result = odbc_exec($con, $query_role);

$num_rows= odbc_num_rows($result);
for($count =1; $count <= $num_rows; $count++)
{
    odbc_fetch_row($result,$count); // fetch the succesive result rows
    
    $taskID= odbc_result( $result, 2 );
    echo "<tr>
		<td>".$taskID."</td><td>".odbc_result( $result, 1 )."</td>
		<td><a href=".$_SERVER 'PHP_SELF']."?action=modify=".$taskID.">modify</a></td>
	 </tr>";
}
odbc_close( $con);
?>
</form>
</tbody>
</table>
 
Hi

If the [tt]$_GET['action'][/tt] you are checking comes from this link :
Code:
<a href=".$_SERVER 'PHP_SELF']."?action=modify=".$taskID.">modify</a>
then its value will be never "modify", so the [tt]if[/tt] condition will never evaluate to true. For example if your $taskID is 2009, the $action will be "modify=2009". Is that intentional ?

Feherke.
 
Hi feherke,

you're spot on! Of course!

But how do I now get the taskID for the task I want to modify in my first SQL statement?

Code:
$query_role="SELECT Tasks FROM  jobdescription2 where TaskID = '????'";
 
Hi

If you modify the generated URL :
Code:
<a href=".$_SERVER['PHP_SELF']."?action=modify[red]&amp;taskid[/red]=".$taskID.">modify</a>
then is simple :
Code:
$query_role="SELECT Tasks FROM  jobdescription2 where TaskID = '[red]".mysql_escape_string($_GET['taskid'])."[/red]'";

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top