2016-08-24 3 views
-1

현재 내 수업 프로젝트에 대한 프로젝트를 진행하고 있습니다. 현재 데이터베이스로 업데이트하려고하지만 기본적으로 업데이트 페이지에 링크하기 위해 라디오 버튼을 설정하는 과정에서 오류가 발생합니다. 모든 도움과 통찰력은 인정 될 것입니다! MySQL 및 PHP 업데이트

<html> 
<head> 
<title>asdf</title> 
<link rel="stylesheet" type="text/css" href="Background.css"> 
</head> 
<?php 
session_start(); 
if(!isset($_SESSION["login"])) 
header("location:admin.php"); 
?> 

<body> 
<h1 style="color:white"><u><center></center></u></h1> 
<div id="BG"></div> 

<form action = "update1.php" method = "GET"> 
    <table border = 0> 
    <tr> 
     <td>Image: <input type = "text" name = "image" id = "image"></td> 
      <br/> 
     <td>Hero Name: <input type = "text" name = "heroes" id = "heroes"></td> 
      <br/> 
     <td>Role: <input type = "text" name = "roles" id = "roles"></td> 
      <br/> 
     <td>Attribute: <input type = "text" name = "attribute" id = "attribute"></td> 
      <br/> 
     <td>Description: <input type = "text" name = "description" id = "description"></td> 
      <br/> 
     <td>General: <input type = "text" name = "general" id = "general"></td> 
      <br/> 
    </tr> 
    </table> 
    </br> 
    <input type = "submit" name="update" value = "Update"> 
</form> 
</center> 
</html> 



<?php 
ini_set('display_errors', 1); ini_set('display_startup_errors', 1);  error_reporting(E_ALL); 
define("DB_USER","*****"); 
define("DB_PASSWORD","****"); 
define("DB_HOST","*****"); 
define("DB_NAME","*****"); 

$dbc=mysqli_connect(DB_HOST,DB_USER,DB_PASSWORD,DB_NAME); 
if(isset($_GET['update'])) 
{ 

    $image = $_GET['image']; 
    $heroes = $_GET['heroes']; 
    $roles = $_GET['roles']; 
    $attribute = $_GET['attribute']; 
    $description = $_GET['description']; 
    $general = $_GET['general']; 
    $sql = "update `Dota 2 select` set (`image` = '$image',`heroes` = '$heroes') WHERE (heroes= '$heroes', image = '$image')"; 
    // $sql = "Update `Dota 2 select` SET (`image`= [$image]) = WHERE `image`)"; 

// $sql = "Update `Dota 2 select` SET (`image`= [$image],`heroes` =[$heroes],`roles` =[$roles],`attribute`=[$attribute],`description`=[$description],`general`=[$general]) = WHERE `heroes`='$heroes')"; 
// $sql = "Update `Dota 2 select` SET (`image`= [$image],`heroes`,`roles`,`attribute`,`description`,`general`) = WHERE (`image`,`heroes`,`roles`,`attribute`,`description`,`general`) =  ('$image','$heroes','$roles','$attribute','$description','$general')"; 

     if(!mysqli_query($dbc, $sql)) 
     { 
echo(mysqli_error($dbc)); 
     } 
     else 
     { 
      echo 'Data successfully updated!'; 
     } 
     mysqli_close($dbc); 
    } 


?> 

이 페이지 " 당신은 당신의 SQL 구문에 오류가 있습니다에 대한 오류입니다 '= ( image를'근처 사용할 수있는 권리 구문에 대한 MySQL 서버 버전에 해당하는 설명서를 확인에 ' , heroes = (영웅 = 'A는'이미지 = 'A') '라인에서 1

"

+0

'A' ='여기 A'. 귀하의 업데이트 구문이 유효하지 않습니다. –

+0

테이블 이름의 이름에 공백이 없어야합니다. – Rahi

+0

@Rahi * "테이블 이름에는 이름에 공백이 없어야합니다"* - 아, 왜 그렇지 않습니까? 그들은 테이블 이름을 벗어났습니다. –

답변

0

당신은 MySQL이 업데이트 구문 혼합 삽입하고 점점 보인다'A ') ..

UPDATE `table` set `col1`='val1', `col2`='val2',.... 
0 그 한 가지 방법보다는

$sql = 'UPDATE `table` set `col1`=\''. $val1.'\', `col2`=\''.$val2.'\',.... 

더 많은처럼 보일 수있는 PHP의 VAR로 설정하지만,이 내 선호하는 방법입니다

. 여기서는 작은 따옴표 문자열을 사용하기 때문에 열 이름 주위의 백틱 및 값 주위의 이스케이프 된 어포 스트로피를 사용합니다.

+0

시도해도 작동하지 않습니다. $ sql = "업데이트 날짜 2를 선택하십시오. SET image = '$ image'WHERE image =". $ image; – RBram

0

테이블 이름의 공간이 잘못되었습니다!

"갱신 Dota_2_select 설정 이미지 = $ 이미지, 영웅 = $ 영웅 곳 영웅 = $ 영웅, 이미지 = $ 이미지";

당신은 당신의 명령을 설정할 수 있습니다 당신이 $ 직접 드 PHP 변수를 호출 할 수 있기 때문에 '대신 "사용하여 테이블 이름 사이의 공백을 제거

0

귀하의 where이 잘못 첫째 :.

WHERE (heroes= '$heroes', image = '$image')"; 

그것은해야

WHERE (heroes= '$heroes' AND image = '$image')"; 
         ^^^^ 

또한 취약한 사람들 sql injection attacks

당신이 당신의 $_GET 값의 존재 여부를 테스트하기 때문에 6,

귀하의 두 번째는 당신이 이미 그것을 사용하여 시도 후에 실패!

if (isset($_GET['Heroes'])) { 
    $Heroes = $_GET['heroes']; 
    ... 
}