2

I have this query;

<?php

$oQuery = mysql_query("SELECT alertboxheader FROM cms_settings");
while($rQuery=mysql_real_escape_string($oQuery)){
echo $rQuery['alertboxheader'];   }
?>

But it doesn't show any texts! I need to get this from the database; http://i50.tinypic.com/30wva0x.png

enter image description here

I hope someone can help me.

Greetings Ray.

John Woo
  • 258,903
  • 69
  • 498
  • 492

2 Answers2

3

Why are you using mysql_real_escape_string? Try, mysql_fetch_assoc

<?php

    $oQuery = mysql_query("SELECT alertboxheader FROM cms_settings");
    while($rQuery = mysql_fetch_assoc($oQuery))
    {
        echo $rQuery['alertboxheader'];   
    }

?>

Please, don't use mysql_* functions in new code. They are no longer maintained and are officially deprecated. See the red box? Learn about prepared statements instead, and use PDO, or MySQLi - this article will help you decide which. If you choose PDO, here is a good tutorial.

Zoe
  • 27,060
  • 21
  • 118
  • 148
John Woo
  • 258,903
  • 69
  • 498
  • 492
  • Thanks for your help, but that code doesn't work. It gives me this error: Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in /home/pinkhotel/domains/pink-hotel.nl/public_html/content/tpl/styles/Habbo/system/header.php on line 170 Line 170 = while($rQuery = mysql_fetch_assoc($oQuery)) – user2252348 Apr 06 '13 at 14:22
  • try running directly `SELECT alertboxheader FROM cms_settings` in ysql if it gives result. – John Woo Apr 06 '13 at 14:24
  • It gives this error, #1054 - Unknown column 'alertboxheader' in 'field list' But on the picture that i gave, you can see it. – user2252348 Apr 06 '13 at 14:25
  • does table `cms_settings` contains `alertboxheader`? – John Woo Apr 06 '13 at 14:26
  • are you sure you are selecting correct database? do you have any dummy database that has almost the same as your current database? – John Woo Apr 06 '13 at 14:29
  • what did you do with your query? – John Woo Apr 06 '13 at 14:49
  • I've maded a new table, and used that one. But i have editted the query you gave me, and it works! Thank you! – user2252348 Apr 06 '13 at 15:06
0

use select value from cms_settings where variable='alertboxheader'; and don't forget what J W said.

nl-x
  • 11,762
  • 7
  • 33
  • 61
  • 1
    grr didnt see the hidden comments. this was anwered an hour ago. Please accept then that was given then. – nl-x Apr 06 '13 at 15:55