詳細を別のフォームページに読み込んで、フォームフィールド値を使用してデータベーステーブルを更新するために、あるページでハイパーリンクを使用したいと考えています。PHP MYSQL FORMS
私は2つのPHPページを持っています。 1つはMYSQLクエリの最後の10レコードのbet_idを返し、もう1つは特定のレコードのすべてのフィールド値をフォームに戻して、エンドユーザにフィールド値を更新する機会を与えます。私は2番目のページで利用されているMYSQLクエリでbet_id '3'を使って2番目のページに移動するように、最初のページのテーブルの3番目の行(bet_id = 3)をクリックすると、フォームフィールドに正しい値をあらかじめ入力してください。
私が問題を抱えているのは、フォームの 'Update bet'ボタンを押したときに入力した新しい値でデータベースを更新することです。ページ2のフォームに表示されているフィールドは、「punter_id」と「category_id」です。誰が何が間違っているかもしれないと示唆することができます私は 'Update bet'ボタンを押すとエラーは出ませんが、フォームフィールドの値は元々のものに戻り、データベーステーブルは$ query(下記参照)で宣言されたクエリによって更新されません。
コードは、以下に含ま:
<?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);
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']);
}
?>
<?
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);
?>
ありがとうIan。あなたが提案したものを試してみましたが、それでも動作しませんでした。 –