调用未定义函数mysql\u select\u db()

qyyhg6bp  于 2021-06-25  发布在  Mysql
关注(0)|答案(2)|浏览(358)

你好,我想显示我的客户信息表,但我不能一个我是新的php。这是我的密码

<?php
mysqli_connect("localhost","root","","company");
mysql_select_db('company');

$sql="SELECT * FROM musteri";

$records = mysql_query($sql);
?>

<html>
<head>
<title>Customer Data</title>
</head>
<body>
<table width="600" border="1" cellpadding="1" cellspacing="1">
    <tr>
        <th>ID</th>
        <th>İsim</th>
        <th>Soyad</th>
        <th>Email</th>
        <th>Doğum Tarihi</th>
    </tr>
    <?php
        while($musteri = mysql_fetch_assoc($records))

        echo "<tr>";
        echo "<td>".$customer['id']."</td>";
        echo "<td>".$customer['age']."</td>";
        echo "<td>".$customer['email']."</td>";
        echo "<td>".$customer['dogumtarih']."</td>";
        echo "</tr>";
    ?>
</table>
</body>
</html>

你能帮帮我吗?我怎样才能解决这个问题。。。

3ks5zfa0

3ks5zfa01#

不能同时使用mysql和mysqli,使用mysqli或mysql作为整个db语法
首先替换第一行代码

$con=mysqli_connect("localhost","root","","company");
$db=$con->mysqli_select_db('company');
uqzxnwby

uqzxnwby2#

更新代码:

<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "company";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 

$sql = "SELECT * FROM musteri";
$result = $conn->query($sql);
?>

<html>
<head>
<title>Customer Data</title>
</head>
<body>
<table width="600" border="1" cellpadding="1" cellspacing="1">
    <tr>
        <th>ID</th>
        <th>Age</th>
        <th>Email</th>
        <th>Doğum Tarihi</th>
    </tr>
    <?php

      if ($result->num_rows > 0) {
    // output data of each row
        while($customer = $result->fetch_assoc()) {

        echo "<tr>";
        echo "<td>".$customer['id']."</td>";
        echo "<td>".$customer['age']."</td>";
        echo "<td>".$customer['email']."</td>";
        echo "<td>".$customer['dogumtarih']."</td>";
        echo "</tr>";

    }
    }
    ?>
</table>
</body>
</html>

相关问题