0

This is conn.php

<?php
ob_start();
session_start();
?>

<?php

$username="root";
$password="";
$sunucu="localhost";
$database="ubys1";

$baglan=mysqli_connect($sunucu,$username,$password);
mysqli_query($baglan,"SET NAMES UTF8");
if($baglan)
{
    mysqli_close($baglan);
    exit();
}

$db=mysqli_select_db($database);
if($db) {
    echo "db error:".mysqli_error(); echo "<br>";

    exit();
}

This is the part for connect db and html codes. After PHP codes, its all HTML.

<?php
include 'admin/conn/conn.php';

$deneme = "SELECT * FROM deneme";
$ayarsor=mysqli_query($baglan,$deneme);
$ayarcek=mysqli_fetch_array($ayarsor);
?>

its giving only blank page, if i write echo on conn.php, it shows the words that i wrote in echo. I'm trying to show the HTML codes but connect the database too.

Martin
  • 22,212
  • 11
  • 70
  • 132
sw1ft
  • 9
  • 1
  • 2
    `if($baglan)` this means if this variable is *truthy* then it will run the if query. Which uses `exit` which will simply stop the script. – Martin Aug 14 '20 at 11:50
  • 3
    _“what should i do?”_ - basic research; always; _before_ you ask. Your question title typed into Google _verbatim_ would have easily led you to one of the duplicates already. – CBroe Aug 14 '20 at 11:54
  • 3
    To be honest, John, the issue is not the error reporting; but it is the failure to debug on the part of the OP. OPs code does a silent exit. – Martin Aug 14 '20 at 11:58
  • 1
    Swift, your code exits the script without **stating why**. This is causing you problems you can't trace -- so you need to update your code (example): `if($baglan) { error_log("MySQL failed to start!!"); exit(); }`. Further to this; your `if` condition is invese, and should be **if fails** not **if succeeds**. So you can do `if(!$baglan){ ...` instead. And apply the same to your `if($db)` conditional as well. – Martin Aug 14 '20 at 11:59
  • Your code produces no output so it makes total sense that the page is empty. Bear in mind that you are not using mysqli correctly. I would recommend learning PDO instead of mysqli because it is easier. https://phpdelusions.net/pdo – Dharman Aug 14 '20 at 11:59

0 Answers0