Page 1 of 1
Re: update a mysql record php issue
Posted: Mon Nov 23, 2015 5:51 am
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.
Re: update a mysql record php issue
Posted: Mon Nov 23, 2015 6:07 am
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.
Re: update a mysql record php issue
Posted: Mon Nov 23, 2015 6:14 am
by Celauran
You've executed the query but you never fetched the results.
Re: update a mysql record php issue
Posted: Mon Nov 23, 2015 6:19 am
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.
Re: update a mysql record php issue
Posted: Mon Nov 23, 2015 6:26 am
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);
Re: update a mysql record php issue
Posted: Mon Nov 23, 2015 7:21 am
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.
Re: update a mysql record php issue
Posted: Mon Nov 23, 2015 7:47 am
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)