What im trying to do is that if in a field in my table [connection Already included, by a config file. YES this works] that if a field is a certain word it will show a piece of code.
<?php
$q = $dbh -> prepare("SELECT * FROM pages_extra WHERE name='page_header'");
$q -> execute(array($_POST['page_header']));
if ($page_header == 'image') {
echo "<center><img src='http://www.freefever.com/stock/animal-abstract-art-wallpaper-hd.jpg' class='img_round' height='500px' width='500px'></center>";
}
?>
Edit:
<?php
$q = $dbh -> prepare("SELECT * FROM pages_extra WHERE name=:page_header");
$q -> execute(array(':page_header' => $_POST['page_header']));
$data_array = $q->fetch();
if ($data_array[0] == 'image') { // what ever your index contains image field
echo "<center><img src='http://www.freefever.com/stock/animal-abstract-art-wallpaper-hd.jpg' class='img_round' height='500px' width='500px'></center>";
}
?>
You have to do something like this:
$data = $q->fetchAll();
$data
now contains an array of associative arrays with the values from the database.
$data[0]["page_header"];
would be the page_header from the first result row.
UPDATE: And if you want to use prepared statements your query should look something like this:
SELECT * FROM pages_extra WHERE name= :page_header
with your array: array("page_header" => $_POST['page_header'])
For further information please check the excellent manual: http://www.php.net/manual/en/pdo.prepare.php
If I'm following your code correctly, I think you're missing the ":" before page_header in the prepare statement.
This code should do the task
<?php
$q = $dbh -> prepare("SELECT * FROM pages_extra WHERE name=:page_header");
$q -> execute(array(':page_header' => $_POST['page_header']));
$data_array = $q->fetch();
if ($data_array[0] == 'image') { // what ever your index contains image field
echo "<center><img src='http://www.freefever.com/stock/animal-abstract-art-wallpaper-hd.jpg' class='img_round' height='500px' width='500px'></center>";
}
?>