Jump to content

Fatal error: Call to undefined function: mysqli_connect()


scrap0346

Recommended Posts

I'm new to PHP and I'm trying to understand the basics of user authentication.  I have a book on PHP and they give the example:

[code]<?php
  $name = $_POST['name'];
  $password = $_POST['password'];

  if(!isset($_POST['name'])&&!isset($_POST['password']))
  {
    //Visitor needs to enter a name and password
?>
  <h1>Please Log In</h1>
  This page is secret
  <form method="post" action="secretdb.php">
  <table border="1">
  <tr>
    <th> Username </th>
    <td> <input type="text" name="name"> </td>
  </tr>
    <th> Password </th>
    <td> <input type="password" name="password"> </td>
  </tr>
  <tr>
    <td colspan="2" align="center">
      <input type="submit" value="Log In">
    </td>
  </tr>
  </table>
  </form>
<?php
  }
  else
  {
  // connect to mysql
  $mysql = mysqli_connect( 'localhost', 'mikemeye_webauth', 'webauth' );
  if(!$mysql)
  {
    echo 'Cannot connect to database.';
    exit;
  }
  // select the appropriate database
  $selected = mysqli_select_db( $mysql, 'auth' );
  if(!$selected)
  {
    echo 'Cannot select database.';
    exit;
  }

  // query the database to see if there is a record which matches
  $query = "select count(*) from authorized_users where
            name = '$name' and
            password = '$password'";

  $result = mysqli_query( $mysql, $query );
  if(!$result)
  {
    echo 'Cannot run query.';
    exit;
  }
  $row = mysqli_fetch_row( $result );
  $count = $row[0];
  if ( $count > 0 )
  {
    // visitor's name and password combination are correct
    echo '<h1>Here it is!</h1>';
    echo 'I bet you are glad you can see this secret page.';
  }
  else
  {
    // visitor's name and password combination are not correct
    echo '<h1>Go Away!</h1>';
    echo 'You are not autorized to view this resource.';
  }
}
?>[/code]


but when I run this, I get the error:

Fatal error: Call to undefined function: mysqli_connect() in /home/mikemeye/public_html/test/secretdb.php on line 32


I did have to manually add the database ("auth"), the username ("mikemeye_webauth"), and password ("webauth") because the script the book gave me didn't work.  Any help would be appreciated.  Thanks!
This meens you haven't got the mysqli extension enabled or not configured properly. Change all occurences of mysqli_* to mysql_* and see if that works.

If not, read [url=http://www.phpfreaks.com/forums/index.php/topic,95378.0.html]this[/url] thread and see if that helps.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.