2009-08-23 3 views
0

남자, 행운이별로 없습니다 ... 나는 시도하고 시도했습니다. 아래 코드를 포함 시켰습니다. Dreamweaver에서 이렇게 재미있는 코드를 수행하고 있습니다. 이것은 편집 페이지입니다. 페이지 1에서이 페이지로 'bet_id'값을 성공적으로 파싱했습니다. 그것은 1 페이지에서 파싱 된 값을 기반으로 올바른 'bet_id'및 'category_id'값으로 양식 필드를 채 웁니다. 양식에서 값을 업데이트 할 때 문제가 발생합니다. 'category_id'값을 업데이트하고 내기 내기 버튼을 누르면 스크립트가 내 데이터베이스의 내기 기록을 업데이트하지 않습니다. 어떤 도움을 많이 주셨습니다. 먼저PHP MYSQL 하이퍼 링크 및 양식 다시

<?php require_once('../Connections/punters_c.php'); ?> 
<?php 
mysql_select_db($database_punters_c, $punters_c); 

$query_Recordset1  = "SELECT bet_id, punter_id,category_id FROM betslip where bet_id =".intval($_REQUEST['bet_id']); 
$Recordset1    = mysql_query($query_Recordset1, $punters_c) or die(mysql_error()); 
$row_Recordset1   = mysql_fetch_assoc($Recordset1); 
$totalRows_Recordset1 = mysql_num_rows($Recordset1); 


##the below function removes dodgy field values 

function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{ 
    $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue; 

    switch ($theType) { 
    case "text": 
     $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; 
     break;  
    case "long": 
    case "int": 
     $theValue = ($theValue != "") ? intval($theValue) : "NULL"; 
     break; 
    case "double": 
     $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL"; 
     break; 
    case "date": 
     $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; 
     break; 
    case "defined": 
     $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; 
     break; 
    } 
    return $theValue; 
} 
$editFormAction = $_SERVER['PHP_SELF']; 
if (isset($_SERVER['QUERY_STRING'])) { 
    $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']); 
} 
?> 
<? 
       // edit.php 
if ((isset($_POST["apply"])) && ($_POST["apply"] == "update_betslip_detail")){ 

     $query = sprintf(" UPDATE betslip 
          SET category_id = '%d' 
          WHERE bet_id = %d", 
          mysql_real_escape($_POST['category_id']), 
          mysql_real_escape($_POST['bet_id']) 
                   ); 

    mysql_select_db($database_punters_c, $punters_c); 
    $Result1 = mysql_query($query, $punters_c) or die('Connection error to MYSQL occurred: '.(mysql_error())); 

     header("Location: /update_betslip_test.php"); 

    } 
    else 
    { 
     echo "bet detail not updated"; 
    } 
    ?> 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /> 
<title>Untitled Document</title> 
</head> 

<body> 
    <form action="<?php echo $editFormAction; ?>" method="POST" enctype="multipart/form-data" name="update_betslip_detail"> 

    <input type="text"  name="bet id"  id = "bet_id"  value="<?php echo $row_Recordset1['bet_id']; ?>"/> 
    <input type="text"  name="category_id" id = "category_id" value="<?php echo $row_Recordset1['category_id']; ?>"/> 


    <input type="hidden" name= "apply"  value="update_betslip_detail"/> 

    <input type="submit" value="Update bet"/> 
    </form> 

    <p><a href="update_betslip_test.php">Back to Update page </a></p> 
</body></html> 
<?php 
mysql_free_result($Recordset1); 
?> 
+0

당신은 정말로 이것을 정리해야합니다, 보리는 읽을 수 있습니다. – 32423hjh32423

+0

Youre right. 죄송합니다. 페이지 1의 레코드 테이블에있는 bet_id 필드에 하이퍼 링크를 사용하여 페이지 2의 폼에 레코드의 세부 정보 (bet_id 및 category_id)를 표시합니다.이 양식 필드를 사용자가 편집 할 수있는 필드로 지정합니다. 베팅 업데이트 버튼을 클릭하여 데이터베이스에서 변경/업데이트 할 수 있습니다. 희망은 더 이해가됩니다. –

+0

또한 문제가있는 데이터베이스 부분에 대한 업데이트임을 확인해야합니다. –

답변

0

, 그래서 (즉, 당신이 자신을 정의한 뭔가하지 않는 한) 그것은 당신에게 치명적인 오류를 제공해야 호출 mysql_real_escape()라는 어떤 기능이 없습니다. 또한 : sprintf(..., '%d')을 사용 중이므로 mysql_real_escape_string() (이스케이프 문자열에 올바른 기능)을 사용할 필요가 없습니다.

관련 메모 (원래 문제와 관련 없음) : GetSQLValueString() 기능에서 addslashes()을 사용하면 안됩니다. 그것도 mysql_real_escape_string()이어야합니다. addslashes()으로 전화하면 합법적 인 입력 (예 : O'BrienO\'Brien)으로 사용할 수 있지만 특정 유형의 악성 입력에는 작동하지 않습니다.