我需要你对我创建的php的帮助。它得到了一个警告,我不知道错误在哪里。
这是我得到的警告:
警告:mysql_query():用户''@ localhost'拒绝访问(使用 密码:NO)在/home/dweetcom/public_html/admin_kepuasan.php上线 10
警告:mysql_query():无法建立指向服务器的链接 在第10行的/home/dweetcom/public_html/admin_kepuasan.php
警告:mysql_fetch_assoc()期望参数1是资源, 在线/home/dweetcom/public_html/admin_kepuasan.php中给出的布尔值 27
这是我的php文件:
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);
?>
答案 0 :(得分:0)
$result=mysqli_query($conn, $sql);
在admin_kepuasan.php文件中,您需要进行以上更改。
第一个参数是连接变量(您在连接文件中创建的)
其次是查询字符串。
答案 1 :(得分:0)
使用以下代码
$conn = new mysqli($servername, $username, $password) or die ("cannot connected");
mysqli_query($conn,"select * from borang_kepuasan");
答案 2 :(得分:0)
试试这个:
$con = mysqli_connect("localhost","dweetcom","8weF5yaMow","dweetcom_borang");
$query = "Enter your query";
mysqli_query($con,$query);
答案 3 :(得分:0)
试试这段代码: &LT; ---- ---- admin_kepuasan.php&GT;
<?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>
这就是连接。 &LT; ---- ----- connection1.php&GT;
<?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);
?>
也不要混用MySQL和MySQLi语法。 MySQL已从PHP 7版本中折旧。