开发者

HTML stops at a PHP script made to connect to a mysql database. No errors printed

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', 'pass开发者_如何学Cword') 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.


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.


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.


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();
}


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜