Jump to content

[SOLVED] mysql_real_escape_string problem


AdRock

Recommended Posts

I have been rewriting my website and I have got a problem with validating user input.

 

I am trying to check against sql injection using mysql_real_escape_string which i have done before but it's not working properly now

 

The errors i am getting are these:

Access denied for user: 'ODBC@localhost' (Using password: NO) in d:\\Apache\\htdocs\\copy of working\\php\\functions.php on line 262

PHP Warning:  mysql_real_escape_string()  Access denied for user: 'ODBC@localhost' (Using password: NO) in d:\\Apache\\htdocs\\copy of working\\php\\functions.php on line 262

PHP Warning:  mysql_real_escape_string()  A link to the server could not be established in d:\\Apache\\htdocs\\copy of working\\php\\functions.php on line 262

 

Here is the function is question

// Function to check user input on the form such as prevent sql injection

function check_input($value)
{
    // Stripslashes
    if (get_magic_quotes_gpc()){
	$value = stripslashes($value);
    }
    // Quote if not a number
    if (!is_numeric($value)){
	$value = mysql_real_escape_string($value);
    }
    return $value;
}

 

There is a connection to the database becuase i call the database functions at the top of the page

 

This is the top part of the page which checks user input

<?php
require_once('php/database/MySQL.php');
require_once('php/database/connection.php');
require_once('php/init.php');
    /**
    * forgotpassword.php is the the page that takes validated values from a form, passing them
    * to the forgot_password function, to create a new password and email it to the user.
    */
    // The title of the page
    $title = "Forgotten Password Recovery";

    // Include the validation classes
    require_once('php/validators/ValidateEmail.php');
    require_once('php/validators/ValidateCaptcha.php');

$useremail ="";

    // Validate the form
    if ( isset ($_POST['recover']) ) {


    	//variables for checking the user's email
    	$email = check_input(trim(strtolower($_POST['email'])));

Any ideas why it's doing this?

 

Link to comment
Share on other sites

db connection resource is not available within a function. Add

global $mysql;  //or whatever your dbconnection is called

as the first line in function.

 

You do not need to specify a connection, the last open connection is used by default.

 

Your connection appears to be failing. Id start debuging there first.

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.