私はこれに非常に新しいので、私のスパゲッティコードを許してください - 私はバスケットボール統計をゲーム中にライブを追跡し、その後、PHPを使用して合計統計を保存するWebページを作ろうとしています。今のところ、私はちょうどボタンを押すと、私のHTMLページからPHPにライブ更新されている変数を渡す必要があります。私はかなり近いとは思えませんが、これを試してみると「未定義のインデックス」というメッセージが表示されています。ここに私のhtmlページは次のとおりです。ライブのJavaScript変数をPHP変数に変換するには?
<head>
<meta charset="utf-8">
<title>Scoring</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
<script type="text/javascript">
var points = 0;
var assists = 0;
var rebounds = 0;
function add1point(){
points++;
document.getElementById('displaypoints').innerHTML = '<p>Points: ' + points;
}
function add2points(){
points = points + 2;
document.getElementById('displaypoints').innerHTML = '<p>Points: ' + points;
}
function add3points(){
points = points + 3;
document.getElementById('displaypoints').innerHTML = '<p>Points: ' + points;
}
function add1assist(){
assists++;
document.getElementById('displayassists').innerHTML = '<p>Assists: ' + assists;
}
function add1rebound(){
rebounds++;
document.getElementById('displayrebounds').innerHTML = '<p>Rebounds: ' + rebounds;
}
</script>
</head>
<body>
<center>
<br>
<button onclick="add1point()">+1 Point (Made Free-Throw)</button>
<br>
<br>
<button onclick="add2points()">+2 Points (Made Field-Goal)</button>
<br>
<br>
<button onclick="add3points()">+3 Points (Made Three-Pointer)</button>
<br>
<br>
<br>
<button onclick="add1assist()">+1 Assist</button>
<br>
<br>
<br>
<button onclick="add1rebound()">+1 (Offensive) Rebound</button>
<br>
<br>
<button onclick="add1rebound()">+1 (Defensive) Rebound</button>
<br>
<br>
<br>
<br>
<form method="post" attribute="post" action="scoring.php">
<div id="displaypoints"><script type="text/javascript">document.write('<p>Points: ' + points);</script></div>
<div id="displayassists"><script type="text/javascript">document.write('<p>Assists: ' + assists);</script></div>
<div id="displayrebounds"><script type="text/javascript">document.write('<p>Rebounds: ' + rebounds);</script></div>
<br>
<br>
<br>
<input type="submit" name="finish" id="finish" value="Finish Game">
</button>
</form>
</center>
</body>
</html>
そして、私のPHPコード:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Game Finished</title>
</head>
<body>
<?php
$points = $_POST['points'];
$assists= $_POST['assists'];
$rebounds = $_POST["rebounds"];
?>
</p>
</body>
すべての任意の助けをいただければ幸いです:)
あなたのフォームが必要 '' 適切な値を「支援する」と「リバウンド」、「ポイント」と呼ばれるフィールド。 – James
@Jamesこれを例に挙げることはできますか? –