ricky spires Posted September 28, 2011 Share Posted September 28, 2011 hello. i have a column called "pageName" and on the each page i have put $pName = "the name of that page". i want to pull from the database all the information where the $pName on the page is the same as the pageName in the database its getting the $pName = "adminHome" but it thinks its the name of the column not the row. this is the error im getting: DATABASE.PHP - confirm_query = MySQL Datatbase Query Failed: Unknown column 'adminHome' in 'where clause' Last SQL query: SELECT * FROM pages WHERE pageName=adminHome this is the function code public static function find_by_pageName($pName=""){ global $database; $sql = "SELECT * FROM ".self::$table_name." WHERE pageName=".$database->escape_value($pName).""; $result_array = self::find_by_sql($sql); return !empty($result_array) ? array_shift($result_array) : false; } this is the page code <?PHP require_once("../includes/initialize.php"); $pName = "adminHome"; $page = Pages::find_by_pageName($pName); ?> thanks rick Quote Link to comment https://forums.phpfreaks.com/topic/248012-whats-wrong-with-my-where-clause/ Share on other sites More sharing options...
Buddski Posted September 28, 2011 Share Posted September 28, 2011 Because the value you are trying to find is a string you need to enclose it in quotes. Try this. $sql = "SELECT * FROM `".self::$table_name."` WHERE `pageName`='".$database->escape_value($pName)."'"; Quote Link to comment https://forums.phpfreaks.com/topic/248012-whats-wrong-with-my-where-clause/#findComment-1273455 Share on other sites More sharing options...
ricky spires Posted September 28, 2011 Author Share Posted September 28, 2011 perfect. that did the trick thanks Quote Link to comment https://forums.phpfreaks.com/topic/248012-whats-wrong-with-my-where-clause/#findComment-1273456 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.