0

Having troubles on why I am not getting a result. I don't get an error and it processes but no results show. Can anyone help me with this?

PHP

$sku= $_POST['sku'];
$sql = "SELECT sku
        FROM location_inventory
        WHERE (sku = 'sku')";
// SQLSRV Query
    $results = sqlsrv_query( $conn, $sql );
    if( $results === false) {
    die( print_r( sqlsrv_errors(), true) );
    }
echo '
            <table border=1>
            <tr>
            <th>Part Number</th>
        </tr>';
while ($row = sqlsrv_fetch_array($results))
{
    echo '
    <tr>
        <td>'.$row[1].'</td>
    </tr>';
}
echo "</table>";

    ?>

HTML

<BODY>
<form action="show.php" method="post">
    <tr>
        <td>
             <input type="text" value="Enter Part Number" name="sku" maxlength="8">
        </td>
    </tr>
    <tr>
        <td align="center" style="font-family:Calibri">
            <input type="submit"  value="Search"/>
    </tr>

eternityhq
  • 105
  • 2
  • 11

4 Answers4

0

Try this :

Replace WHERE (sku = 'sku')"

With    WHERE (sku = $sku)";
Devang Rathod
  • 6,650
  • 2
  • 23
  • 32
0

try this

$sql = "SELECT sku
    FROM location_inventory
    WHERE sku = '$sku'";
sudhakar
  • 582
  • 1
  • 3
  • 13
0

You don't pass $sku to your select string. Try this:

$sql = "SELECT `sku` FROM `location_inventory` WHERE (`sku` = '" . $sku . "')";

Also make sure to escape all your inputs you use for your database queries, check this question for more info.

Ah I forgot: Use ini_set('display_errors', 1) and error_reporting(E_ALL) at the start of your file to get all errors.

Community
  • 1
  • 1
Fortuna
  • 611
  • 6
  • 18
  • I added the error reporting line to my files and it's working like a charm. Already helping me. Thanks :) as soon as I can upvote it shall me done. – eternityhq Aug 19 '13 at 13:43
0

Along with what sudhakar said, you should try outputting $row[0] instead of $row[1] since I'm guessing you will only have 1 row of data (if each sku is unique).

wiscWeb
  • 213
  • 1
  • 13