bugzy Posted April 12, 2012 Share Posted April 12, 2012 I'm getting this error Notice: Use of undefined constant mysql_error - assumed 'mysql_error' in C:\wamp\www\zhee_corp\includes\functions.php on line 8 Database query failed: mysql_error This is my code <?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); confirm_query($result_set); if($subject = mysql_fetch_array($result_set)) { return $subject; } else { return NULL; } } ?> My Sql Connection <?php require("constants.php"); //Selecting the Server $connection = mysql_connect(DB_SERVER, DB_USER, DB_PASS); if(!$connection) { die("Database Connection Failed: ". mysql_error()); } //Selecting the Database $db_select = mysql_select_db(DB_NAME, $connection); if(!$db_select) { die("Database Selelction Failed: ". mysql_error()); } ?> When I'm trying to call that function in a page it gives me an error, I wonder what the problem is.. Anyone? Quote Link to comment Share on other sites More sharing options...
bugzy Posted April 12, 2012 Author Share Posted April 12, 2012 I'm calling that function here: <?php require_once("includes/connection.php"); ?> <?php require_once("includes/functions.php"); ?> <?php if(isset($_GET['subj'])) { $sel_subj = $_GET['subj']; $sel_page = ""; } elseif (isset($_GET['page'])) { $sel_subj = ""; $sel_page = $_GET['page']; } else { $sel_page = ""; $sel_subj = ""; } ?> <?php $sel_subject = get_subject_by_id($sel_subj); ?> I'm so confused what causing the error... Quote Link to comment Share on other sites More sharing options...
Jessica Posted April 12, 2012 Share Posted April 12, 2012 You need to post functions.php line 8. Most likely you wrote mysql_error and forgot the (). Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted April 12, 2012 Share Posted April 12, 2012 The error is occurring on line 8 of functions.php. So far, nothing you have posted is where that error is at. It would be a line such as ... die('some message here...' .mysq_error); which should actually be ... die('some message here...' . mysql_error()); (i.e. you are missing the () which would identify it as a call to a function.) Quote Link to comment Share on other sites More sharing options...
bugzy Posted April 12, 2012 Author Share Posted April 12, 2012 You need to post functions.php line 8. Most likely you wrote mysql_error and forgot the (). Hey thanks! You're guys are right, I forgot the () on mysql_error. Now I have this error 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 my MySql version is 5.1.36... Anyone? Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted April 12, 2012 Share Posted April 12, 2012 Have you looked at the actual query statement that is failing to see if you can tell what is wrong with it (i.e. we cannot help you with what is wrong with it since we have not seen it or the code that is producing it either.) Quote Link to comment Share on other sites More sharing options...
bugzy Posted April 12, 2012 Author Share Posted April 12, 2012 Have you looked at the actual query statement that is failing to see if you can tell what is wrong with it (i.e. we cannot help you with what is wrong with it since we have not seen it or the code that is producing it either.) Not sure if this is what you're talking about, but here's the function and the query that I'm having problem with.. <?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); confirm_query($result_set); if($subject = mysql_fetch_array($result_set)) { return $subject; } else { return NULL; } } ?> I'm just wondering if there's a mysql compatability issue with "LIMIT" on my query.. I have posted some of the codes from my above codes as well... Quote Link to comment Share on other sites More sharing options...
bugzy Posted April 12, 2012 Author Share Posted April 12, 2012 I have tried the same query at phpMyAdmin and also got this error #1064 - 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 '= 1' at line 1 Quote Link to comment Share on other sites More sharing options...
Jessica Posted April 12, 2012 Share Posted April 12, 2012 It's just LIMIT 1. No = . Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted April 12, 2012 Share Posted April 12, 2012 Edit: Sorry to keep reposting the same answers you have already given jesirose. There's no = sign as part of the LIMIT clause. The following is the SELECT syntax definition - SELECT [ALL | DISTINCT | DISTINCTROW ] [HIGH_PRIORITY] [sTRAIGHT_JOIN] [sql_SMALL_RESULT] [sql_BIG_RESULT] [sql_BUFFER_RESULT] [sql_CACHE | SQL_NO_CACHE] [sql_CALC_FOUND_ROWS] select_expr [, select_expr ...] [FROM table_references [WHERE where_condition] [GROUP BY {col_name | expr | position} [ASC | DESC], ... [WITH ROLLUP]] [HAVING where_condition] [ORDER BY {col_name | expr | position} [ASC | DESC], ...] [LIMIT {[offset,] row_count | row_count OFFSET offset}] [PROCEDURE procedure_name(argument_list)] [iNTO OUTFILE 'file_name' [CHARACTER SET charset_name] export_options | INTO DUMPFILE 'file_name' | INTO var_name [, var_name]] [FOR UPDATE | LOCK IN SHARE MODE]] Quote Link to comment Share on other sites More sharing options...
bugzy Posted April 12, 2012 Author Share Posted April 12, 2012 Ok here the modified query with "LIMIT 1" on it <?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); confirm_query($result_set); if($subject = mysql_fetch_array($result_set)) { return $subject; } else { return NULL; } } ?> I'm still getting 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 As you can see on the code, there's a proper spacing already on the query.. ? I'm confused! Quote Link to comment Share on other sites More sharing options...
Jessica Posted April 12, 2012 Share Posted April 12, 2012 Echo the query. You probably don't have a value in $subject_id. BEAT YA AGAIN!!!! :-P Quote Link to comment Share on other sites More sharing options...
bugzy Posted April 12, 2012 Author Share Posted April 12, 2012 Echo the query. You probably don't have a value in $subject_id. BEAT YA AGAIN!!!! :-P You are right again... There's seems to be a problem on my if statement code that whenever I call that function it's giving me a wrong url and no value on the get statement for $subject_id. Again.. Thank to both of you for helping me out. Quote Link to comment 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.