2009-08-23 7 views
0

みんな、運があまりない...私は試してみました。以下のコードを含んでいます。 Dreamweaverでこれをやっているので面白いコードです。これは編集ページです。ページ1からこのページに「bet_id」という値を正常に解析しました。これは、フォームフィールドに正しい 'bet_id'と 'category_id'の値をページ1から解析した値に基づいて設定します。フォームの値を更新すると問題が発生します。 「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に変更)が、特定の種類の悪意のある入力に対しては機能しません。

関連する問題