0

I'm trying to create a template that fetches a row of data from a database based on the URL variables ?=1&?b=siteurl for example. when http://www.example.com/?a=1&?b=siteurl is visited, I'd like to display all of the information from that specific row, example- the title.

    $id = $_GET['a'];
    $dp = $_GET['b'];
    $stmt = $mysqli->prepare( "select option_id,option_name,option_value from tablename WHERE option_id = ? AND option_name = ?");
    $stmt->bind_param("is", $id, $dp );
    $stmt->execute();
    $result = $stmt->get_result();
    if($result->num_rows > 0){
    while ($row = $result->fetch_assoc()) {
    echo '<span id="show">',"{$row['value']}",'</span>' ;
    }
  }
}

I think it's working because I don't receive any error, but no data showing up, if I run this query in phpMyAdmin I receive data that I want to get.

Dharman
  • 30,962
  • 25
  • 85
  • 135
Sam Tumuli
  • 15
  • 2

1 Answers1

0

The reason you are getting a white page is probably due a syntax error. Looking at your code you're concatenating (joining) strings with a , -- in PHP you concatenate variables with a . so your echo statement should be:

echo '<span id="show">' . $row['value'] . '</span>';.

A second thing I noticed is your URL mark-up; only use the ? once in a link (it signals the start of the variables). To specify multiple variables in your link, separate them with &. So your example link should be: http://www.example.com/?a=1&b=siteurl.

As a last note, to avoid getting a blank page instead of an error page, make sure error reporting is on in PHP. Putting this in the header of your file should work:

ini_set('display_startup_errors', 1);
ini_set('display_errors', 1);
error_reporting(E_ALL);

Don't forget to remove it later to avoid leaking application errors to strangers.

ArendE
  • 957
  • 1
  • 8
  • 14
  • i was follow your advice but now i receive error:Undefined index: value,its in this line echo '',"{$row['value']}",'' ; – Sam Tumuli Jan 23 '21 at 09:44
  • That means that the index you want does not exist in the result. Looking at your query it should probably be `$row['option_value']`. You can check what is in your row object by doing a `var_dump($row);` in your while loop; it will show you all the values then. – ArendE Jan 26 '21 at 14:06