Categories: Uncategorized

PHP sql returns space in email address while query with json post data using post method

I have faced a scenario where I was getting space error in the email address before @ symbol in email address, as I were making simple post request to verify the login.
Json post object sample:

{
 "email": "test@example.com",
   "password" : "test123"
}

Was returning error in response of like test @example.com so the email address was not getting verified in the database.

Upon google came to following stack overflow result for solution but not satisfy with the approach of replacing single quote again and forcing self to post the email address with single quote in post request, which is obviously not a good solution. (later I have commented on the result page with my solution 😉 )
Simply I did this at query level and it resolve the space issue in the email address while query in database.

$query = "SELECT * FROM 
            " . $this->table_name . " 
            WHERE email =  '".$this->email."'  LIMIT 0,1";

Finally, wrapped the email address variable with the single quotes, and resolved the issue of space before @ symbol.

Hope this solution and result page will save your day!

admin

Recent Posts

The Ultimate Guide to Effective Meetings

In today’s fast-paced work environment, meetings are essential but can often feel unproductive. However, by…

2 months ago

From Mine to Market: How Gold Is Mined, Refined, and Sold in Shops

Gold is one of the most coveted precious metals in the world, adored for its…

3 months ago

The Historical Journey of Gold: From Ancient Civilizations to Modern Times

Gold, the shimmering metal synonymous with wealth, power, and beauty, has been deeply intertwined with…

3 months ago

How to Onboard an Intern in Small, Individual-Based Company

How to Onboard an Intern in a Small, Individual-Based Company Hiring an intern can be…

4 months ago