你好,我有活動和非活動圖像代碼鏈接到數據庫表提交的狀態。有效和無效
現在,當我點擊激活或無效的記錄,所以它不工作。
下面是代碼:
的index.php
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<?PHP
$user_name = "root";
$password = "";
$database = "tariq";
$server = "localhost";
$db_handle = mysql_connect($server, $user_name, $password);
$db_found = mysql_select_db($database, $db_handle);
if ($db_found) {
$SQL = "SELECT * FROM active";
$result = mysql_query($SQL);
while ($db_field = mysql_fetch_assoc($result)) {
if($db_field['status'] == 'Active')
{
echo "<a href='activate.php?status= Inactive' ><img src = 'inactive.jpg' /></a>";
}
else
{
echo "<a href='activate.php?status= Active' ><img src = 'active.jpg' /></a>";
}
}
mysql_close($db_handle);
}
else {
print "Database NOT Found ";
mysql_close($db_handle);
}
?>
</body>
</html>
活動.PHP
<?php
$status = $_GET['status'];
$con=mysqli_connect("localhost","root","","tariq");
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
if($status == 'Active')
{
mysqli_query($con,"UPDATE `active` SET `status` = 'Inactive'");
}
else
{
mysqli_query($con,"UPDATE `active` SET `status` = 'Active'");
}
header('location:tariq.php');
mysqli_close($con);
?>
什麼「不工作?」 –
字段狀態未在數據庫中更新我已將查詢粘貼到phpmyadmin工作的界面中 – user3295655
當您點擊(active/inactive)鏈接並轉到'active.php'後重新加載'index.php'時發生了什麼? ?它會改變狀態圖像嗎? – SaidbakR