0

I am unable to connect my sql server from PHP, kindly help in letting me know where I am going wrong ?

<!DOCTYPE html>
    <html>
    <head>
    <meta charset="ISO-8859-1">
    <title>Insert title here</title>
    </head>
    <body>
    <?php
    $servername = "x.x.x.x";
    $username = "xx";
    $password = "xxxxx";

    // Create connection
    $conn = mysqli_connect($servername, $username, $password);

    // Check connection
    if (!$conn) {
        die("Connection failed: " . mysqli_connect_error());
    }
    else {
        echo"Succesfull";
    }
    $sql = "SELECT TOP 1000 [Service_provider],[Account_No],[MDN_No],
    [IP_Address],[Sim_No],[Status],[RatePlan] ,[Sim_Type FROM [Sampledata].
    [dbo].[sampletableforsimcardstatus]";
    $result = $conn->query($sql);

    if ($result->num_rows > 0) {
        echo "<table><tr><th>Account_No</th><th>Service_provider</th>
    <th>MDN_No</th></tr>";
        // output data of each row
        while($row = $result->fetch_assoc()) {
            echo "<tr><td>" . $row["Account_No"]. "</td><td>" . 
    $row["Service_provider"]. " " . $row["MDN_No"]. "</td></tr>";
        }
        echo "</table>";
    } else {
        echo "0 results";
    }

    $conn->close();


    ?>
    </body>
    </html>

And i get the code written as an output on webpage:

ERROR:

query($sql); if ($result->num_rows > 0) { echo ""; // output data of each row while($row = $result->fetch_assoc()) { echo ""; } echo " Account_No Service_provider MDN_No " . $row["Account_No"]. " " . $row["Service_provider"]. " " . $row["MDN_No"]. " "; } else { echo "0 results"; } $conn->close(); ?>

F0XS
  • 1,271
  • 3
  • 15
  • 19

0 Answers0