So the code below on a website I'm revising [links pulled from database now] works perfect and prints out the matching row and column to the html. There is a column for short names[name2, VARCHAR] and an auto incrementing integer column[id] to match.
function rainmaker($fname) {
$connect = new PDO('mysql:host=localhost;dbname=weather;', '******', '***');
$sql = $connect->query('SELECT `link` FROM `satellite` WHERE `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 is shown on site.
However, every variation of this via ID fails (1064 error: the variable $urllink is empty) or doesn't print out the image link (site works, except that the images aren't shown).
$sql = $connect->query('SELECT `link` FROM `satellite` WHERE `id` = "'.$fname.'"');
....
<TD ALIGN="CENTER"><P><?php rainmaker('1'); ?></P></TD>
Fail!
Any idea why? Is it because the ID column is an integer?
EDIT:
I have prepared statment w/ placeholder variations of this fucntion but I simplified since I'm having a seperate issue where this function isn't accepting my global variavbles to identify the table when the select query is like like:
function rainmaker($fname) {
$connect = new PDO('mysql:host=localhost;dbname=weather;', '******', '***');
$psql = $connect->prepare('SELECT `link` FROM ? WHERE `id` = ?');
$psql->execute(array($table,$fname));
while ($result = $psql->fetch()){
$urllink = $result['link'];}
$linky = fullLinkedThumbnail($urllink,150);
print $linky;}
I can't pass the table name and the sql query reports failure. Not sure why but I assume I made some syntax errors. For now, I'll just need this issue solved.
If I run select query for ID through phpadmin, it matches and prints out the row just fine so there isn't a mismatch with a null value.