0

Hello there i want to display my customer information from table but i can not an i am new in php. This is my code

<?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>

Can you please help me? How can i fix this...

Cugurel
  • 99
  • 1
  • 3
  • 9
  • first check you are connect db using mysqli and select db using mysql why? – Reena Mori May 11 '18 at 10:45
  • 1.) Store the object returned by mysqli_connect(...), eg. $mysql 2.) use $mysql->select_db(...) ... or don't go with 'i' and use Reena Mori's approach. – Flocke May 11 '18 at 10:48
  • https://www.w3schools.com/php/php_mysql_select.asp llok into db connection in php on here – G43beli May 11 '18 at 10:49
  • 1
    Possible duplicate of [Can I mix MySQL APIs in PHP?](https://stackoverflow.com/questions/17498216/can-i-mix-mysql-apis-in-php) – CD001 May 11 '18 at 10:52
  • Not to mention the `mysql_` extension is obsolete so you need to move everything to `mysqli` or `pdo` – CD001 May 11 '18 at 10:53
  • 1
    @Cugurel: Please check updated code. – PPL May 11 '18 at 10:59

2 Answers2

1

Updated code:

<?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>
PPL
  • 6,101
  • 1
  • 10
  • 28
0

You can`t use mysql & mysqli together, Use mysqli either mysql for whole db syntax

first replace your first line code

$con=mysqli_connect("localhost","root","","company");
$db=$con->mysqli_select_db('company');
Reena Mori
  • 647
  • 6
  • 15