0

Please I need help identifying the problem with my query here:

So this is my hard-coded data because I am trying to test my PHP script on its own with out the android application that usually sends data to it.

I have this array of hardcoded data.

$register_data = array(
    'username'  => 'david',
    'password'  => 'david',
    'first_name'    => 'david',
    'last_name'     => 'david',
    'email'     => 'david@yahoo.com'
);

This is my problematic query:

"SELECT * FROM `user_info` WHERE `email` = '$register_data['email']' OR `username` = '$register_data['username']'";

And this is the error i received:

Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) in /home1/ifedavid/public_html/androidconnect/register.php

Please is there something I'm doing wrong? Thanks for the help in advance.

semilogo97
  • 125
  • 1
  • 2
  • 11
  • The quotes within the array syntax is throwing it off. You can eliminate them, use braces around the variable instead, **OR use prepared statements and parameter binding so you'll never have to worry about quoting issues ever again (or SQL injection)** – aynber Oct 06 '17 at 19:26

1 Answers1

0
$register_data = array(
    'username'  => 'david',
    'password'  => 'david',
    'first_name'    => 'david',
    'last_name'     => 'david',
    'email'     => 'david@yahoo.com'
);

$query = "SELECT * FROM 'user_info' WHERE 'email' = '".$register_data['email']."' OR 'username' = '".$register_data['username']."'";

Then execute the query with the var $query

Hope it helps