?
Solved

SQL query works in SQL editor but returns no results in PHP

Posted on 2014-02-20
5
Medium Priority
?
308 Views
Last Modified: 2014-02-25
Hi All,

   I'm having an issue with PHP returning results on a query.  It returns results when I use the SSMS but not in PHP.  I'm perplexed...  (ignore the lack of css lol)

		$telno = $_POST['telno'];

	$newtelno = preg_replace("/[^0-9]/", "", $telno);

	$sql = "select [dbo].[MERCHANT].*, replace(replace([MERCHANT].[CONTACT_PHONE], '-', ''), ' ', '') as CTPHONE from [dbo].[MERCHANT] where replace(replace([dbo].[MERCHANT].[CONTACT_PHONE], '-', ''), ' ', '') = '" . $newtelno . "'";

	$stmt = sqlsrv_query( $conn, $sql );
	if( $stmt === false) {
	    die( print_r( sqlsrv_errors(), true) );
	}

	$row_count = sqlsrv_num_rows( $stmt );
	echo "Row Count: " . $row_count . "<br>";

	while( $row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_ASSOC) ) {

 		echo "<tr><td valign=\"top\" bgcolor=$bgcc><font size=4 face=\"Arial\">" . $row[0] . "</td><td bgcolor=$bgcc valign=\"top\"><font size=3 face=\"Arial\">" . $row[1] . "</td><td valign=\"top\" bgcolor=$bgcc><font font size=3 face=\"Arial\">" . $row[2] . "</td><td valign=\"top\" bgcolor=$bgcc><font font size=3 face=\"Arial\">" . $row[3] . "</td><td valign=\"top\" bgcolor=$bgcc><font font size=3 face=\"Arial\">" . $row[4] . "</td><td valign=\"top\" bgcolor=$bgcc><font font size=3 face=\"Arial\">" . $row[5] . "</td><td valign=\"top\" bgcolor=$bgcc><font font size=3 face=\"Arial\">" . $row[6] . "</td><td valign=\"top\" bgcolor=$bgcc><font font size=3 face=\"Arial\">" . $row[7] . "</td></tr>";
		echo "<tr><td>&nbsp;</td></tr>";

	}

	sqlsrv_free_stmt( $stmt);

Open in new window

0
Comment
Question by:IT Tech
  • 3
5 Comments
 
LVL 24

Expert Comment

by:mankowitz
ID: 39873732
What error is it giving you? Can you post some sample data and a use-case?
0
 

Accepted Solution

by:
IT Tech earned 0 total points
ID: 39873746
It's not giving an error at all, it's just not returning any results which has me confused.  I'm currently just taking an identical script and changing it again in case I screwed up something lol.
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 39873782
When you say "not returning any results" what is the output from line 13?
0
 

Author Comment

by:IT Tech
ID: 39873792
I figured it out myself.
0
 

Author Closing Comment

by:IT Tech
ID: 39885122
I figured it out - I was pulling an associative array instead of numeric.
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
This month, Experts Exchange sat down with resident SQL expert, Jim Horn, for an in-depth look into the makings of a successful career in SQL.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses
Course of the Month13 days, 20 hours left to enroll

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question