-1

I'm very new to MySQL, and I'm having some trouble echoing the values from a table. For the code I have here, the output is totally blank. Where am I going wrong? Is it with the loop?

<?php    
    $a = 1;
    $b = 2;


    $con = mysqli_connect ();
    //Check Connection
    if (mysqli_connect_errno())
      {
      echo "Failed to connect to MySQL: " . mysqli_connect_error();
      }

    $table = "CREATE TABLE info (id INT NOT NULL AUTO_INCREMENT, city CHAR(40), country CHAR(40))" or die(mysql_error());

    $table = mysqli_query($con, "INSERT INTO info (city, country) VALUES ($a, $b)) or die(mysql_error()") or die(mysql_error());

    $result = mysqli_query("SELECT * FROM info") or die(mysql_error());  

    while($row = mysql_fetch_array( $result )) {
        echo $row['city'];
        }

    mysqli_close($con);

    ?>
4

1 回答 1

1

You are mixing two different extensions. What you want, as others have said, is mysqli_fetch_array().

On top of that, unless I'm mistaken.. you don't actually connect to any database. As noted in the documentation, you have to put connection information in the object when you call it(although this is optional if you just want the object, and don't want to connect just yet).

于 2013-03-31T03:12:26.177 回答