views:

52

answers:

4

I'm trying to set up a login script for PHP using the tutorial on this site. The problem is that the site stops when it hits these lines, no error, no text:

<?php
$conn = mysql_connect('localhost', 'root', 'password') or die('error line7' . mysql_error());
mysql_select_db('mydb', $conn) or die('error line8' . mysql_error());
?>

If I take out these lines, the rest of the html runs perfectly. I've double checked my passwords and everything, nothing is working. I know very little about php and mysql other than what I've learned trying to set this up.

+1  A: 

Maybe you don't have errors enabled.

Try enabling them before those lines like so

error_reporting(E_ALL & ~E_NOTICE); 
ini_set('display_errors', '1');

Good luck.

Drew LeSueur
That answers a lot. It was a problem with my server. Lacking a module.
DavidR
A: 

Do something like this:

$mysqli = new mysqli("localhost", "root", "password", "database");

/* check connection */
if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
}

if ($result = $mysqli->query("YOUR QUERY")) {
    while($row = $result->fetch_row()){
        // do what you want with resutls
    }
    $result->close();
}
GaVrA
+1  A: 

Beside all the other tips, which are good ones, Learn to tail -f the apache error log and the mysql log (all the possible logs which make sense to follow).
While in development. that is.

Itay Moav
A: 

Check that the MySQL extensions are enabled in your install PHP. You can check by putting the following in one file and falling from the browser:

 <?
     phpinfo();
 ?>

It's a lengthy page, but it tells you almost everything about your PHP install. Including what extensions are installed.

staticsan