[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

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

Posted on 2014-02-20
5
Medium Priority
?
306 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.
Suggested Courses

650 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