我不知道为什么我的表格不起作用,这是我的代码: 添加单词因为无法发布编辑.......................................... .... P.S 所有其他代码完美无缺!!!
页面:1:
<button id="Head" onclick="rollHead()">Head</button>
<button id="Tail" onclick="rollTail()">Tail</button>
<script>
function rollTail(){
var die1 = document.getElementById("die1");
var status = document.getElementById("status");
var d1 = Math.floor(Math.random() * 2) + 1;
if(d1 == 1)
{
die1.innerHTML = "You won!";
fliped.innerHTML = "Fliped Tail!";
var ajax = new XMLHttpRequest();
ajax.open('POST','won.php',true);
ajax.send();
}
else if (d1 == 2)
{
die1.innerHTML = "You lose!";
fliped.innerHTML = "Fliped Head!";
var ajax = new XMLHttpRequest();
ajax.open('POST','lose.php',true);
ajax.send();
}
}
function rollHead(){
var die1 = document.getElementById("die1");
var status = document.getElementById("status");
var d1 = Math.floor(Math.random() * 2) + 1;
if(d1 == 1)
{
die1.innerHTML = "You lose!";
fliped.innerHTML = "Fliped Tail!";
var ajax = new XMLHttpRequest();
ajax.open('POST','lose.php',true);
ajax.send();
}
else if (d1 == 2)
{
//alert(document.getElementById('wonorlose').value );
die1.innerHTML = "You won!";
fliped.innerHTML = "Fliped Head!";
var ajax = new XMLHttpRequest();
ajax.open('POST','won.php',true);
ajax.send();
}
}
</script>
<form method="get" action="won.php">
<h2 align="center">
<input type="text" name="wonorlose" value=50>
</h2>
</form>
Page:won.php:
<?php
include_once 'dbconnect.php';
session_start();
if(!isset($_SESSION['user']))
{
header("Location: /manopuslapis/index.php");
}
$res=mysql_query("SELECT * FROM users WHERE user_id=".$_SESSION['user']);
$userRow=mysql_fetch_array($res);
$wonorlose = $_GET["wonorlose"];
echo $wonorlose;
mysql_query("UPDATE `users` SET credits=credits+'$wonorlose' WHERE user_id=".$_SESSION['user']);
?>
答案 0 :(得分:0)
此行int[] array;
var results = new List<Tuple<int[], int[]>>();
for (int i = 0; i < array.Length; i++) {
var tuple = SplitIntArray(array, i);
if (tuple.Item1.Sum() == tuple.Item2.Sum()) {
results.Add(tuple);
}
}
// results contains all pairs of arrays that sum to the same value.
foreach (var tuple in results) {
Console.WriteLine(
String.Format("{0} == {1}", AggregateSumString(tuple.Item1), AggregateSumString(tuple.Item2)));
}
出现问题
won.php
你有$res=mysql_query("SELECT * FROM users WHERE user_id=".$_SESSION['user']);
作为字符串..这必须是整数 OR 你必须添加引号:
$_SESSION['user']
或者在$res=mysql_query("SELECT * FROM users WHERE user_id='".$_SESSION['user']."'");
之后添加$_SESSION["user"]
,将(int)
定义为整数。
<强>更新强>
teamviewer解决了问题。用户得到空白变量=
,因为他在没有参数的情况下进行AJAX POST。我使用参数$wonorlose
将AJAX POST更改为AJAX GET,现在它正常工作。最终代码只有作者。