I need your help about the php that i create. it got a warning and, i dont know where the mistake is.
This is the warning that i get:
Warning: mysql_query(): Access denied for user ''@'localhost' (using password: NO) in /home/dweetcom/public_html/admin_kepuasan.php on line 10
Warning: mysql_query(): A link to the server could not be established in /home/dweetcom/public_html/admin_kepuasan.php on line 10
Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in /home/dweetcom/public_html/admin_kepuasan.php on line 27
This is my php file:
admin_kepuasan.php
<?php
include("connection1.php");
?>
<html>
<link rel="stylesheet" type="text/css" href='https://cdn.datatables.net/1.10.13/css/jquery.dataTables.min.css'/>
<?php
$sql="select * from borang_kepuasan";
$result=mysql_query($sql);
echo "<table id='example' class='display' cellspacing='1' width='100%'>";
echo "<thead>";
echo "<tr>";
echo "<td>Soalan 1</td>";
echo "<td>Soalan 2</td>";
echo "<td>Soalan 3</td>";
echo "<td>Soalan 4</td>";
echo "<td>Soalan 5</td>";
echo "<td>Soalan 6</td>";
echo "<td>Soalan 7</td>";
echo "<td> Nota / Testimoni </td>";
echo "</tr>";
echo "</thead>";
echo "<tbody>";
while ($row = mysql_fetch_assoc($result)) {
echo "<tr>";
echo "<td>$row[soalan1]</td>";
echo "<td>$row[soalan2]</td>";
echo "<td>$row[soalan3]</td>";
echo "<td>$row[soalan4]</td>";
echo "<td>$row[soalan5]</td>";
echo "<td>$row[soalan6]</td>";
echo "<td>$row[soalan7]</td>";
echo "<td>$row[nota]</td>";
echo "</tr>";
}
echo "</tbody>";
echo "</table>";
echo "<center>";
echo "<table>";
echo "<tr>";
echo "<td>";
echo "<button style=height:30px width:80px value=Kembali onClick=location.href='admin1.php'>";
echo "Kembali";
echo "</button>";
echo "</td>";
echo "<td>";
echo "<button style=height:30px width:80px value=Log Out onClick=location.href='logout.php'>";
echo "Log Out";
echo "</a>";
echo "</button>";
echo "</center>";
?>
</html>
<script src='//code.jquery.com/jquery-1.12.4.js'></script>
<script src='https://cdn.datatables.net/1.10.13/js/jquery.dataTables.min.js'></script>
<script>
$('#example').DataTable();
</script>
connection1.php
<?php
$servername = "localhost";
$username = "dweetcom";
$password = "8weF5yaMow";
// Create connection
$conn = new mysqli($servername, $username, $password) or die ("cannot connected");
@mysql_select_db("dweetcom_borang",$conn);
?>
$result=mysqli_query($conn, $sql);
In admin_kepuasan.php file, you need above change.
First parameter is the connection variable (which you created in connection file)
Second is the query string.
Use below code
$conn = new mysqli($servername, $username, $password) or die ("cannot connected");
mysqli_query($conn,"select * from borang_kepuasan");
Try this :
$con = mysqli_connect("localhost","dweetcom","8weF5yaMow","dweetcom_borang");
$query = "Enter your query";
mysqli_query($con,$query);
Try this code: <----admin_kepuasan.php---->.
<?php
require_once 'connection1.php';
?>
<html>
<link rel="stylesheet" type="text/css" href='https://cdn.datatables.net/1.10.13/css/jquery.dataTables.min.css'/>
<?php
$sql="select * from borang_kepuasan";
$result=mysqli_query($conn,$sql);
echo "<table id='example' class='display' cellspacing='1' width='100%'>";
echo "<thead>";
echo "<tr>";
echo "<td>Soalan 1</td>";
echo "<td>Soalan 2</td>";
echo "<td>Soalan 3</td>";
echo "<td>Soalan 4</td>";
echo "<td>Soalan 5</td>";
echo "<td>Soalan 6</td>";
echo "<td>Soalan 7</td>";
echo "<td> Nota / Testimoni </td>";
echo "</tr>";
echo "</thead>";
echo "<tbody>";
if (mysqli_num_rows($result) > 0) {
while ($row = mysqli_fetch_assoc($result)) {
echo "<tr>";
echo "<td>$row[soalan1]</td>";
echo "<td>$row[soalan2]</td>";
echo "<td>$row[soalan3]</td>";
echo "<td>$row[soalan4]</td>";
echo "<td>$row[soalan5]</td>";
echo "<td>$row[soalan6]</td>";
echo "<td>$row[soalan7]</td>";
echo "<td>$row[nota]</td>";
echo "</tr>";
}
} else {
echo "0 results";
}
echo "</tbody>";
echo "</table>";
echo "<center>";
echo "<table>";
echo "<tr>";
echo "<td>";
echo "<button style=height:30px width:80px value=Kembali onClick=location.href='admin1.php'>";
echo "Kembali";
echo "</button>";
echo "</td>";
echo "<td>";
echo "<button style=height:30px width:80px value=Log Out onClick=location.href='logout.php'>";
echo "Log Out";
echo "</a>";
echo "</button>";
echo "</center>";
?>
</html>
<script src='//code.jquery.com/jquery-1.12.4.js'></script>
<script src='https://cdn.datatables.net/1.10.13/js/jquery.dataTables.min.js'></script>
<script>
$('#example').DataTable();
</script>
And this is the connection. <----connection1.php----->
<?php
$servername = "localhost";
$username = "dweetcom";
$password = "8weF5yaMow";
// Create connection
$conn = new mysqli($servername, $username, $password) ;
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
@mysqli_select_db("dweetcom_borang",$conn);
?>
Also don't mix MySQL and MySQLi syntax. MySQL has been depreciated from PHP 7 versions.