Chris
Chris

Reputation: 85

PHP return results from MySQL Query

I'm fairly new to PHP, but here is my issue, I am trying to get the results from a SQL query to display on the page, but I'm not getting anything returned.

Here is the code that I'm currently working with:

    <?php

$con = mysqli_connect("localhost","user","password","database");
if (mysqli_connect_errno()) {
    echo "Connect failed: ". mysqli_connect_error();
}

$de= $con->real_escape_string($_GET["decode"]);

$sql = "select * from FG99_URL where short='".$de."'";
$result = mysqli_query($con, $sql);

while($row = mysqli_fetch_assoc($result)) {
        echo "url: " . $row["url"]. " - fb_url: " . $row["fb_url"]."<br>";

$url=$row['url'];
$fb_url=$row['fb_url'];
$fb_type=$row['fb_type'];
$fb_title=$row['fb_title'];
$fb_description=$row['fb_description'];
$fb_image=$row['fb_image'];
$petpro=$row['petpro'];

echo $fb_url.'test 1</br>';
echo $row['fb_url'] . "test 2</br>";

print $fb_url."test 3</br>";
print $row['fb_url']."test 4</br>";

   }
?>

<head>...

This is what I get returned:

url: - fb_url: 
test 1
test 2
test 3
test 4

Any help would be appriciated.

Upvotes: 1

Views: 85

Answers (2)

Younghwa Park
Younghwa Park

Reputation: 392

Check your database first.

After set sql query, try this code:

$sql = "select * from FG99_URL where short='".$de."'";

echo $sql;

Copy and paste sql query into DB client like mysqladmin.

Upvotes: 0

Kannaiyan
Kannaiyan

Reputation: 13025

Do a var_dump($row) and see what is in the row variable.

That will help to see whether you have those data in those returning data set.

Based on the output, you are getting some data and returning data might not have the columns you are looking for.

Hope it helps.

Upvotes: 1

Related Questions