Jump to content

Unable to query mysql with email address from post


ddarsow

Recommended Posts

I am trying to query a MySQL database based on a user's email address which is posted from a form. The posted data echos fine, but when I use the variable to query the database I get 0 rows returned. If I use the exact same query, substituting the desired email address instead of pulling it from a variable value the query works. I assume it has something to do with the @ symbol not being interpreted correctly after being posted, but this is admittedly merely a guess. Any idea how to remedy this?

 

The relevant code is as follows:

 

The for posting the email address:

<form action="secure/prepare.php" method="post" onsubmit="this.submit(); return false" >
Please enter your email address:<br>
<input type="text" name="mail" value="<?echo$mail?>" size="40"><br><br>
<input type="submit" value=" Proceed to Checkout ">
</form>

 

The variable value & query on the next page:

$mail=$_POST["mail"];

$query="SELECT * FROM customers WHERE cust_email = '$mail' ";

 

I intentionally left all other code out as everything works perfect if I simply change the query to something like:

$query="SELECT * FROM customers WHERE cust_email = 'name@domain.com' ";

Link to comment
Share on other sites

Where is $mail defined?  You sure it has a value...?

 

Umm...seriously?

It is defined with:

$mail=$_POST['mail'];

 

Yes, I am sure it has a value as the page is in a test environment & not live yet so I am posting the value myself from the form. Also if I echo the variable on the page it returns the expected value such as:

echo $mail;

returns whatever was entered into the form such as user@domain.com

 

Link to comment
Share on other sites

  • 2 weeks later...
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.