Jump to content

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

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

That shows where $e is being set. How about $p?

 

Do you have an "or die" clause on the mysql_query() function:

<?php
$rs = mysql_query($query) or die("Problem with the query: $query<br>" . mysql_error());
?>

 

Ken

 

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());

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?

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 />";

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

It's not being used elsewhere at all.

 

I commented out the function and removed the calls from the script and it drags the correct fields into the variables.

 

The SELECT still fails but that's something else for me to ponder over!

 

Thanks for you help, Mark

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.