0
   $CustomerName= preg_replace('/[^a-zA-Z0-9-_\.,& ]/','',$row["Customer_Name"]);
   array_push($CustomerName2,$CustomerName);
   $sqlquery = "SELECT * FROM Customer where Customer_Name IN ($CustomerName2)";
   $stmt = mysql_query($conn,$sqlquery);
   echo(print_r(sqlsrv_errors(), true));
   while( $row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_NUMERIC))    
   {    
       $sqlCustomerIdMaps[$row[0]]= $row[0];
   }

I am not well with php, in above php code querying data from sql .My output is from array $CustomerName2 like:

Array ( [0] => Acme Janitor & Chemical Supply [1] => Adam Zampa [2] => AMAZON.COM PHOENIX PHX6 [3] => Aston Agar [4] => Austin Consulting Group [5] => Brad Hodge [6] => Cedrick Johnson [7] => Crowen [8] => David Miller [9] => David Warner [10] => DKR [11] => DKR [12] => DKR [13] => Jaworskyj Gabrielle [14] => Johan2 [15] => Jone [16] => Keith Olson [17] => Mallika [18] => Manoj Reddy [19] => Michael Bevan [20] => Philip Andry [21] => Shane1 Warne1 [22] => Spad Consulting Group [23] => Usman Khawaja [24] => Zohar )

In sql query i am not getting any errors but query is not working?

I need to query with Customer_Name and add result to map to update data in sql server.

Can anybody help me to resolve this issue.

Thanks in advance!

1 Answer 1

1

Your problem is that $CustomerName2 is an array, and you are trying to use it as a string when you make your query. Change that code to:

$sqlquery = "SELECT * 
    FROM Customer
    WHERE Customer_Name IN ('" . implode("','", $CustomerName2) . "')";

Update

You are using the wrong database library to fetch your data. Based on the fact that you are connecting to a MySQL database using the mysqli library, you should rewrite the last part of your code to:

$result = mysqli_query($conn, $sqlquery);
echo mysqli_errno($conn);
while ($row = mysqli_fetch_array($result) {
    $sqlCustomerIdMaps[$row[0]]= $row[0];
}
Sign up to request clarification or add additional context in comments.

13 Comments

Thanks for your replay.
When i replace with your suggetion, i am getting "PHP Parse error: syntax error, unexpected ';'" this error.
Sorry I had a couple of typos. See my edited answer.
Thanks you for your patience to answer me.
Array ( [0] => Array ( [0] => IMSSP [SQLSTATE] => IMSSP [1] => -14 [code] => -14 [2] => An invalid parameter was passed to sqlsrv_query. [message] => An invalid parameter was passed to sqlsrv_query. ) ) getting this error...
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.