update a mysql record php issue

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: update a mysql record php issue

Post by Celauran »

Precisely as the error indicates, $row is undefined. I'm not sure what value that is meant to contain, but there's no $row = anywhere in that code.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: update a mysql record php issue

Post by Celauran »

$row is defined only within the scope of that function, not in the global scope, which is where you're trying to echo the description.

http://php.net/manual/en/language.variables.scope.php

Additionally, description is not part of your select statement, so wouldn't be returned anyway.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: update a mysql record php issue

Post by Celauran »

You've executed the query but you never fetched the results.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: update a mysql record php issue

Post by Celauran »

You still need to call fetch or fetchAll. Incidentally, you can pass the fetch mode as an argument to either of those methods.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: update a mysql record php issue

Post by Celauran »

Code: Select all

$sql=$dbh->prepare("SELECT
      e.emp_id
    , t.task_id
    , t.description
    , t.status
    FROM employee e
    JOIN assignment a ON e.emp_id = a.emp_id
    JOIN task t ON a.task_id = t.task_id
    WHERE e.emp_id = ?");
$sql->execute(array($_SESSION['user']));
$row = $sql->fetch(PDO::FETCH_ASSOC);
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: update a mysql record php issue

Post by Celauran »

ianhaney wrote:in my address bar, it has task_id=3 but the description it is pulling out is task_id
Your query is using session data, so what's in the address bar is irrelevant.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: update a mysql record php issue

Post by Celauran »

The short answer is you'd want $_GET['task_id'], though there may be other considerations at play (ie. does the current user have permission to access the task in question, etc)
Post Reply