Jump to content

HELP: Use of undefined constant mysql_error


bugzy

Recommended Posts

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?

Link to comment
Share on other sites

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...

Link to comment
Share on other sites

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.)

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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...

 

Link to comment
Share on other sites

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

 

:shrug:

Link to comment
Share on other sites

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]]

 

 

 

 

Link to comment
Share on other sites

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! :(

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.