• 10
name

A PHP Error was encountered

Severity: Notice

Message: Undefined index: userid

Filename: views/question.php

Line Number: 191

Backtrace:

File: /home/prodcxja/public_html/questions/application/views/question.php
Line: 191
Function: _error_handler

File: /home/prodcxja/public_html/questions/application/controllers/Questions.php
Line: 433
Function: view

File: /home/prodcxja/public_html/questions/index.php
Line: 315
Function: require_once

try
{
    if ($db = mysqli_connect($hostname_db, $username_db, $password_db))
    {
        //do something
    }
    else
    {
        throw new Exception('Unable to connect');
    }
}
catch(Exception $e)
{
    echo $e->getMessage();
}
  • 13
Reply Report
      • 1
    • i need to replace die("Unable to connect with Database"); with your code? Also can you tell me what is @$_POST['variable']
    • You should replace your last line with this. @ - is enabling silent mode, no error will be echoed but still logged in your server's error.log file. I guess you know what $_POST['variable'] is.
      • 2
    • one more thing, as i have added the code in an include_db file for database connection... so what i should put in the area //do something because it just need to do connect or show the error...
      • 1
    • You can leave that empty, if there's no error the execution will continue with code what is after the try...catch block.

It is documented here http://ie2.php.net/manual/en/mysqli.error.php

if (mysqli_connect_errno()) {
    throw new RuntimeException("Connect failed: %s\n", mysqli_connect_error());
}
  • 3
Reply Report
      • 2
    • ok $db = mysqli_connect($hostname_db, $username_db, $password_db) or die("Unable to connect with Database"); I have to replace with this $db = mysqli_connect($hostname_db, $username_db, $password_db); if (mysqli_connect_errno()) { throw new RuntimeException("Connect failed: %s ", mysqli_connect_error()); }

Warm tip !!!

This article is reproduced from Stack Exchange / Stack Overflow, please click

Trending Tags

Related Questions