-1

Okay - I must be having a brain lapse. The code below is showing "Successful Connection" but the data is not being displayed. What am I overlooking?

BTW - I triple checked the DB name, table and fields - so they are correct.

<?php 

// - - - - - - - - - - - - - - - - *
// include("config.php"); 
// - - - - - - - - - - - - - - - - *

$servername = "localhost";
$username = "****";
$password = "****";
$dbname = "****";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection

if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
} else {
    echo "Connection Successful - ";
}

$sql="SELECT * FROM teams ORDER BY team";
$result=mysql_query($sql);                      // Puts result in a variable 
$count=mysql_num_rows($result);                 // Counts number of rows (records)

while($rows=mysql_fetch_array($result)){
    echo $rows['team']; 
    echo '<br />';   
}
echo "<p>hell yes</p>";


?>

Hopefully this will be a simple overlook on my part.

user1438038
  • 5,821
  • 6
  • 60
  • 94
NetTemple
  • 319
  • 1
  • 13
  • The database is ****, The table is "teams", the field is "team" – NetTemple Oct 28 '15 at 15:02
  • You're connection with `mysqli_` and querying with `mysql_` functions. Those are two different libraries, and do not work together – andrewsi Oct 28 '15 at 15:03
  • Can you post the correct connect string? While I google what you are pointing out.... – NetTemple Oct 28 '15 at 15:03
  • You should keep the mysqli_connect, as the mysql_ functions are deprecated. Instead use `mysqli_query` to get at your data: http://php.net/manual/en/mysqli.query.php – andrewsi Oct 28 '15 at 15:04
  • Will do Fred. But I did do a search before posting the question. The problem is there are so many "different flavors" to the same type of question and a lot of deprecated answers. But I understand that we don't want to little the system with dupes. Understood. – NetTemple Oct 28 '15 at 15:11

1 Answers1

1

You use a mysqli connection and mysql functions. Don't mix this up!

http://php.net/manual/en/book.mysql.php

http://php.net/manual/en/book.mysqli.php

Example with mysql:

// - - - - - - - - - - - - - - - - *
// include("config.php"); 
// - - - - - - - - - - - - - - - - *

$servername = "localhost";
$username = "****";
$password = "****";
$dbname = "****";

// Create connection
mysql_connect($servername, $username, $password);
mysql_select_db($dbname);

$sql="SELECT * FROM teams ORDER BY team";
$result=mysql_query($sql);                      // Puts result in a variable 
$count=mysql_num_rows($result);                 // Counts number of rows (records)

while($rows=mysql_fetch_array($result)){
    echo $rows['team']; 
    echo '<br />';   
}
echo "<p>hell yes</p>";

But like andrewsi mentioned, you should use mysqli.

tino.codes
  • 1,512
  • 1
  • 12
  • 23