Jump to content

Error connecting to mysql server


pourmeanother

Recommended Posts

Using the following code I receive "Error" as the output -- meaning I'm not successfully connecting to the MySQL server.

 

PHP4

mysql server version 4.1.14

phpMyAdmin 2.11.9

MySQL client version 3.23.49

(Not sure which of the above is required information)

 

    <?php
    $host="localhost";
    $user="user";
    $password=" ";
    $database="databasename";

    $cxn = mysql_connect($host, $user, $password);
    if(!$cxn)
    {
         exit("Error");
    }
    $db_selected = mysql_select_db($database);
    if(!$db_selected)
    {
         exit("Could not connect");
    }

    $query = "SELECT * FROM AdamsChristen";
    $result = mysql_query($query, $cxn);
    if(!$result)
    {
       exit("Data currently unavailable");
    }

    while( $row = mysql_fetch_assoc($result) )
    {
       extract($row);
       echo "<table cellspacing='15'>";
       echo "<tr><td colspan='5'><hr></td></tr>\n";
       echo "<tr>
             <td>$semester$year</td>
             <td><b>Helpfulness:</b>\n$helpfulness</td>
             <td><b>Ease of Grading:</b>\n$grading</td>
             <td><b>Attention Factor:</b>\n$interesting</td>
             <td><b>Attendance Mandatory:</b>\n$attendance</td>
             <td><b>Comments:</b>\n$comments</td>
             </tr>\n";
       echo "<tr><td colspan='5'><hr></td></tr>\n";
    }

    echo "</table>";

    mysql_close($cxn);
    ?>

 

Trying to troubleshoot. All help is appreciated!

Link to comment
https://forums.phpfreaks.com/topic/130227-error-connecting-to-mysql-server/
Share on other sites

change this.

    $cxn = mysql_connect($host, $user, $password);
    if(!$cxn)
    {
         exit("Error");
    }

 

to this...

    $cxn = mysql_connect($host, $user, $password) or die(mysql_error());

 

see what you get then

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.