peter Ojeda
asked on
Select from sql by results from textbox
Hi experts, I have a table in my database with the columns MONTH_ and YEAR_. I am trying to display this by using a select statement that the WHERE field comes from textbox inputs. My idea is SELECT * FROM D_LINE_MONTH DATA WHERE YEAR=(TEXTBOX RESULTS) AND YEAR = (TEXTBOX RESULTS). My two text boxes are also MONTH_ and YEAR_. I keep getting the error "Warning: sqlsrv_fetch_array() expects parameter 1 to be resource, boolean given "
<?php
ini_set('display_errors', 1);
error_reporting(~0);
$serverName = "vnmwhatsup\PWRBI_REPORTS";
$userName = "appuser";
$userPassword = 'appuser';
$dbName = "ENERGY";
$strID = null;
if(isset($_GET["ID"]))
{
$strID = $_GET["ID"];
}
$connectionInfo = array("Database"=>$dbName, "UID"=>$userName, "PWD"=>$userPassword, "MultipleActiveResultSets"=>true);
$conn = sqlsrv_connect( $serverName, $connectionInfo);
if( $conn === false ) {
die( print_r( sqlsrv_errors(), true));
}
$stmt = "SELECT * FROM D_LINE_MONTH_DATA WHERE YEAR_ = + 'YEAR_' AND MONTH_ = + 'MONTH_'";
$params = array($strID);
$query = sqlsrv_query( $conn, $stmt, $params);
$result = sqlsrv_fetch_array($query, SQLSRV_FETCH_ASSOC);
?>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Almost all PHP functions return values. Your PHP script can test these values to see what the function did. Check the code examples in the man pages.
http://php.net/manual/en/function.sqlsrv-connect.php
http://php.net/manual/en/function.sqlsrv-query.php
http://php.net/manual/en/function.sqlsrv-connect.php
http://php.net/manual/en/function.sqlsrv-query.php
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi thank you both for your help. I was able to get it to work by setting and concatenating the input variables and it works perfectly.
You are welcome.
ASKER