Php/Mysql: cannot print output to html selecting from table when match by ID but names works? -
so code below on website i'm revising [links pulled database now] works perfect , prints out matching row , column html. there column short names[name2, varchar] , auto incrementing integer column[id] match.
function rainmaker($fname) { $connect = new pdo('mysql:host=localhost;dbname=weather;', '******', '***'); $sql = $connect->query('select `link` `satellite` `name2` = "'.$fname.'"'); while ($result = $sql->fetch()){ $urllink = $result['link'];} $linky = fulllinkedthumbnail($urllink,150); print $linky; }
further down....
<td align="center"><p><?php rainmaker('ato'); ?></p></td>
success! image shown on site.
however, every variation of via id fails (1064 error: variable $urllink empty) or doesn't print out image link (site works, except images aren't shown).
$sql = $connect->query('select `link` `satellite` `id` = "'.$fname.'"'); .... <td align="center"><p><?php rainmaker('1'); ?></p></td>
fail!
any idea why? because id column integer?
edit:
i have prepared statment w/ placeholder variations of fucntion simplified since i'm having seperate issue function isn't accepting global variavbles identify table when select query like:
function rainmaker($fname) { $connect = new pdo('mysql:host=localhost;dbname=weather;', '******', '***'); $psql = $connect->prepare('select `link` ? `id` = ?'); $psql->execute(array($table,$fname)); while ($result = $psql->fetch()){ $urllink = $result['link'];} $linky = fulllinkedthumbnail($urllink,150); print $linky;}
i can't pass table name , sql query reports failure. not sure why assume made syntax errors. now, i'll need issue solved.
if run select query id through phpadmin, matches , prints out row fine there isn't mismatch null value.
don't concatenate strings, breaks , can used sql injections.
use prepared statements placeholders instead.don't try find thumbmail, if no rows in satellite matched condition.
Comments
Post a Comment