Solved

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

Posted on 2014-02-20
5
298 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 108

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

867 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now