Jump to content

[SOLVED] SELECT Statement Syntax for Variables


rawky1976

Recommended Posts

Hello all

 

I've just got a quick question, the statement below isn't returning the expected results. I've echoed it at runtime and the variables are missing. I presume it's just the syntax?

 

$query = "SELECT field FROM database.table WHERE email='$e' AND password='$p'";

 

Can anyone help please?

 

Mark

Link to comment
Share on other sites

Use Single quotes around the entire string and double quotes around the variables.

 

Hello all

 

I've just got a quick question, the statement below isn't returning the expected results. I've echoed it at runtime and the variables are missing. I presume it's just the syntax?

 

$query = "SELECT field FROM database.table WHERE email='$e' AND password='$p'";

 

Can anyone help please?

 

Mark

Link to comment
Share on other sites

The code for $p is the same as $e but for password field instead of email.

 

I've added the die but it hasn't printed any errors on the page: -

 

$query = "SELECT userid FROM knowledgebase.users WHERE email='$e' AND password='$p'";
    $result = mysql_query($query) or die("Problem with the query: $query<br>" . mysql_error());

Link to comment
Share on other sites

OK thanks, I added: -

 

echo "TEST E: $e";

echo "TEST P: $p";

 

and it outputs: -

 

TEST E: TEST P:

The email address and current password do not match those in the database.

 

SELECT userid FROM knowledgebase.users WHERE email='' AND password=''

 

Is it a setting with the quotes or something rather than the script?

Link to comment
Share on other sites

The problem is for whatever reason those variables have no contents.

 

Can you show us your escape_data function?

 

Also can you try this:

 

replace this:

$e = escape_data($_POST['email']);

 

with this:

echo "BEFORE: " . $_POST['email'] . "<br />";

$e = escape_data($_POST['email']);

echo "AFTER: $e<br />";

Link to comment
Share on other sites

Before shows my email address!!!

After shows: -

 

AFTER: TEST E: TEST P:

 

Here is the function (it's out of a book).

 

function escape_data ($data) {
  global $dbc;
    if (ini_get('magic_quotes_gpc')) {
      $data = stripslashes($data);
    }
    return mysql_real_escape_string(trim($data), $dbc);
  }

 

Thanks again, Mark

Link to comment
Share on other sites

So, just as expected, the culprit is that escape_data function.

 

Where are you using $dbc elsewhere in your code? I'd have to read up on mysql_real_escape_string but I think that the problem is it's not a valid database handle.

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.