2017-07-03 9 views
-4

私は最初のデータベースをオンラインにしました。 phpmyadminを使用して、テーブルとユーザーを作成しました。
私は自分のサイトのページにテーブルを表示し、サイトからデータベースを編集する可能性を与えたいと思います。
私の問題は、データベースが機能しないということです。接続しません。私は何をすべきか分かりません。
私のデータベースはとなります。letstenf_santiと私のテーブルpasseggeriとなります。 これは、サイト上の表を表示するために使用しようとしているコードです。これに代えてMySQLが動作していないようです

<?php 
//establishing connection 
mysql_connect('localhost', 'root', ''); 
//selecting a database 
mysql_select_db('letstenf_santi'); 
$sql = 'SELECT * FROM `letstenf_santi`.`passeggeri`'; 
$records=mysql_query($sql); 
?> 

<html> 
<head> 
    <title>mostra</title> 
</head> 
<body> 
<table width="300" border="1" cellpadding="10" cellspacing="1"> 
<tr> 
<th>id pass</th> 
<th>nome</th> 
<th>eta</th> 
<th>sesso</th> 
</tr> 
<?php 
while($pass=mysql_fetch_assoc($records)){ 
    echo "<tr>"; 
echo "<td>".$pass['idpasseggero']."</td>"; 
echo "<td>".$pass['nome']."</td>"; 
echo "<td>".$pass['eta']."</td>"; 
echo "<td>".$pass['sesso']."</td>"; 
echo "</tr>"; 
} 
?> 
</table> 
</body> 
</html> 
+3

非推奨の構文は –

+0

あなたが取得しているエラーが何を検出し、このコードを試してみてください? –

+0

なし。それだけでは機能しません。私は何をすべきかわからない – gab

答えて

0

、 にmysql_connect( 'localhostの'、 '根'、 '')。 mysql_select_db( 'letstenf_santi');

あなたはこれを試すことができ、

$接続=にmysql_connect( 'localhostの'、 'ルート'、 '');

$ db = mysql_select_db( 'letstenf_santi'、$ connection);

+0

まだ動作しません:/ – gab

+0

私はあなたが得ているエラーは何ですか? –

+0

この "mysql_fetch_assoc"をこの "mysql_fetch_array"に変更してください –

0

<?php 
$servername = "localhost"; 
$username = "root"; 
$password = ""; 
$dbname = "letstenf_santi";//your db name 

// Create connection 
$conn = mysqli_connect($servername, $username, $password, $dbname); 
// Check connection 
if (!$conn) { 
    die("Connection failed: " . mysqli_connect_error()); 
} 

$sql = "SELECT * FROM tablename";//replace table name with your table name 
$result = mysqli_query($conn, $sql); ?> 
<html> 
<head> 
    <title>mostra</title> 
</head> 
<body> 
<table width="300" border="1" cellpadding="10" cellspacing="1"> 
<tr> 
<th>id pass</th> 
<th>nome</th> 
<th>eta</th> 
<th>sesso</th> 
</tr> 
<?php if (mysqli_num_rows($result) > 0) { 
    // output data of each row 
    while($row = mysqli_fetch_assoc($result)) { 
     echo "<tr>"; 
echo "<td>".$row['idpasseggero']."</td>"; 
echo "<td>".$row['nome']."</td>"; 
echo "<td>".$row['eta']."</td>"; 
echo "<td>".$row['sesso']."</td>"; 
echo "</tr>"; 
    } 
} else { 
    echo "0 results"; 
} 

mysqli_close($conn); 
?> 
</table> 
</body> 
</html> 
+0

それは動作します!本当にありがとう – gab

関連する問題