2014-02-23 3 views
0

안녕하세요, 나는 status라는 파일에 저장된 데이터베이스 테이블에 대한 링크 인 활성 및 비활성 이미지에 대한 코드를 가지고 있습니다.활성 및 비활성

이제 활성 상태 또는 비활성 상태를 클릭하여 작동하지 않을 때. 여기

코드입니다 :

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); 
?> 
+2

"작동하지 않습니까?" –

+0

필드 상태가 데이터베이스에서 업데이트되지 않습니다. phpmyadmin 인터페이스에 쿼리를 붙여 넣습니다. – user3295655

+0

(활성/비활성) 링크를 클릭하고'active.php'로 이동 한 후'index.php'를 다시로드하면 어떻게됩니까? ? 상태 이미지가 변경됩니까? – SaidbakR

답변

1

브라우저에서

<a href='activate.php?status= Inactive' > 
          ^.............here 

에 공백이 때 내가 볼 링크를 클릭하십시오. 이케 status=%20Inactive

<a href='activate.php?status= Active' > 
          ^.............here 

$status = trim($_GET['status']); 

는 또한 mysqli_real_escape_string()

으로 GET 값을 소독

로)합니다 (GET 값을 트림 항상

<a href='activate.php?status=Inactive' > 
<a href='activate.php?status=Active' > 

과 공간을 제거하고

+0

$ space = ''; $ check = mysqli_real_escape_strin ($ con, $ space); // 작동하지 않습니다 – user3295655

+0

죄송합니다. mysqli_real_escape_string() http://in3.php.net/mysqli_real_escape_string –

+0

여전히 작동하지 않습니다 – user3295655

0

페이지 이름 확인 활성 또는 활성화 ??

관련 문제