Search the Community
Showing results for tags 'sql query error in php'.
-
SQL QUERY PROBLEM IN PHP. I m using windows xp O.S. I have installed WAMP for learning and practicing PHP. when I execute the following code i m getting an error.I M INCLUDING A FUNCTION FILE(functions.php) IN MY content.php file.MY ALL OTHER FUNCTIONS AND SQL QUERIES ARE WORKING EXCEPT THIS ONE. ---------------------------------------------------------------------------------------------------------------- functions.php(c:/wamp/www/widget_corp/includes/functions.php) function get_subject_by_id($subject_id){ global $connection; $query = "SELECT * "; $query .= "FROM subjects "; $query .= "WHERE id=".$subject_id; $query .= "LIMIT 1"; $result_set = mysql_query($query,$connection); if(!$result_set){ die("database query failed:".mysql_error()); } //if no rows are returned, then fetch array is going to return false if($subject = mysql_fetch_array($result_set)) { return $subject; } else { return NULL; } } ----------------------------------------------------------------------------------------------------------------- content.php(c:/wamp/www/widget_corp/content.php) <?php require("constants.php"); //Creating a database connection $connection = mysql_connect(DB_SERVER,DB_USER,DB_PASSWORD); if(!$connection){ die("DATABASE CONNECTION FAILED:".mysql_error()); } ?> <?php //Selecting a database $db_connect = mysql_select_db(DB_NAME,$connection); if(!$db_connect){ die("Database selection failed:".mysql_error()); } ?> <?php //including functions.php ?> <?php require_once($_SERVER['DOCUMENT_ROOT']."/widget_corp/includes/functions.php") ?> <?php //$_GET['subj'] and $_GET['page'] are returning my subjects and pages ids respectively. ?> <?php if(isset($_GET['subj'])){ $sel_subj = $_GET['subj']; $sel_pg=""; }elseif(isset($_GET['page'])){ $sel_pg= $_GET['page']; $sel_subj = ""; } else { $sel_subj = ""; $sel_pg = ""; } $sel_subject = get_subject_by_id($sel_subj); $sel_page = get_page_by_id($sel_pg); ?> ------------------------------------------------------------------------------------------------------------------ ERROR(ON BROWSER): database query failed:You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'LIMIT 1' at line 1