gpt4 book ai didi

php - undefined index 传递变量与 javascript 到 php

转载 作者:行者123 更新时间:2023-11-30 18:55:23 25 4
gpt4 key购买 nike

我正在用 JS jquery 制作一个“更新”页面..

但是在我的 updateit.php 中,我在所有字段上都得到了 undefined index 。我不知道为什么。

这是表格:

<form action="javascript:updateit()" method="post"> 
<b>+ Giv points for at være online:</b><br>
Points hvert. <input type="text" size="1" id="gpe" name="gpe" value="<?=$row["gpe"]; ?>"> Sekundt.<br>
<b>+ Hvor mange points skal der gives(online):</b><br>
<input type="text" name="gpm" id="gpm" size="1" value="<?=$row["gpm"]; ?>"> Points.<br>
<b>+ Points for videoklip:</b><br>
<input type="text" name="gpv" id="gpv" size="1" value="<?=$row["gpv"]; ?>"> Points.<br>
<b>+ Points for battle:</b><br>
<input type="text" name="gpb" id="gpb" size="1" value="<?=$row["gpb"]; ?>"> Points.<br>
<b>+ Points for kommentar:</b><br>
<input type="text" name="gpk" id="gpk" size="1" value="<?=$row["gpk"]; ?>"> Points. & + <b>for 10 kommentare:</b>
<input type="text" name="gpk10" id="gpk10" size="1" value="<?=$row["gpk10"]; ?>"> Points.<br>
<b>+ Points for spil:</b><br>
<input type="text" name="gpg" id="gpg" size="1" value="<?=$row["gpg"]; ?>"> Points.<br>
<b>+ Points for sjov:</b><br>
<input type="text" name="gps" id="gps" size="1" value="<?=$row["gps"]; ?>"> Points.<br>
<b>+ Points for SC tryout:</b><br>
<input type="text" name="gpsc" id="gpsc" size="1" value="<?=$row["gpsc"]; ?>"> Points.<br>
<b>+ Points for første gang redigering i profil:</b><br>
<input type="text" name="gpep" id="gpep" size="1" value="<?=$row["gpep"]; ?>"> Points.<hr>
<b>- Points for at fjerne videoklip:</b><br>
<input type="text" name="gpRv" id="gpRv" size="1" value="<?=$row["gpRv"]; ?>"> Points.<br>
<b>- Points for at fjerne battle:</b><br>
<input type="text" name="gpRb" id="gpRb" size="1" value="<?=$row["gpRb"]; ?>"> Points.<br>
<b>- Points for at fjerne indhold i "Sjov" sektionen:</b><br>
<input type="text" name="gpRs" id="gpRs" size="1" value="<?=$row["gpRs"]; ?>"> Points.<br>
<b>- Points for at fjerne tutorial:</b><br>
<input type="text" name="gpRt" id="gpRt" size="1" value="<?=$row["gpRt"]; ?>"> Points.<br>
<b>- Points for at fjerne spil:</b><br>
<input type="text" name="gpRg" id="gpRg" size="1" value="<?=$row["gpRg"]; ?>"> Points.<br>
<input type="submit" name="Submit" value="Opdater!"/>
</form>
<div id="insert_response"></div>

更新it.php:

<?php
$gpm= $_POST['gpm'];
$gpe= $_POST['gpe'];
$gpv= $_POST['gpv'];
$gpb= $_POST['gpb'];
$gpk= $_POST['gpk'];
$gpk10= $_POST['gpk10'];
$gpg= $_POST['gpg'];
$gps= $_POST['gps'];
$gpsc= $_POST['gpsc'];
$gpep= $_POST['gpep'];
$gpRv= $_POST['gpRv'];
$gpRb= $_POST['gpRb'];
$gpRg= $_POST['gpRg'];
$gpRs= $_POST['gpRs'];
$gpRt= $_POST['gpRt'];
mysql_query("INSERT INTO member_pointsystem (gpm, gpe, gpv, gpb, gpk, gpk10, gpg, gps, gpsc, gpep, gpRv, gpRb, gpRg, gpRs, gpRt) VALUES ('$gpm', '$gpe' ,'$gpv', '$gpb', '$gpk', '$gpk10', '$gpg', '$gps', '$gpsc', '$gpep', '$gpRv', '$gpRb', '$gpRg', '$gpRs', '$gpRt')") or
die(mysql_error());
echo "works";
?>

(我知道我在 PHP 中的变量不安全,但我只是在测试..)

和脚本:

/* ---------------------------- */
/* XMLHTTPRequest Enable */
/* ---------------------------- */
function createObject() {
var request_type;
var browser = navigator.appName;
if(browser == "Microsoft Internet Explorer"){
request_type = new ActiveXObject("Microsoft.XMLHTTP");
}else{
request_type = new XMLHttpRequest();
}
return request_type;
}

var http = createObject();
/* -------------------------- */
/* INSERT */
/* -------------------------- */
/* Required: var nocache is a random number to add to request. This value solve an Internet Explorer cache issue */
var nocache = 0;
function updateit() {
// Optional: Show a waiting message in the layer with ID login_response
document.getElementById('insert_response').innerHTML = "Arbejder.. "
// Required: verify that all fileds is not empty. Use encodeURI() to solve some issues about character encoding.
var gpe= encodeURI(document.getElementById('gpe').value);
var gpm= encodeURI(document.getElementById('gpm').value);
var gpv=encodeURI(document.getElementById('gpv').value);
var gpb= encodeURI(document.getElementById('gpb').value);
var gpk= encodeURI(document.getElementById('gpk').value);
var gpk10= encodeURI(document.getElementById('gpk10').value);
var gpg= encodeURI(document.getElementById('gpg').value);
var gps= encodeURI(document.getElementById('gps').value);
var gpsc= encodeURI(document.getElementById('gpsc').value);
var gpep= encodeURI(document.getElementById('gpep').value);
var gpRv= encodeURI(document.getElementById('gpRv').value);
var gpRb= encodeURI(document.getElementById('gpRb').value);
var gpRg= encodeURI(document.getElementById('gpRg').value);
var gpRs= encodeURI(document.getElementById('gpRs').value);
var gpRt= encodeURI(document.getElementById('gpRt').value);
// Set te random number to add to URL request
nocache = Math.random();
// Pass the login variables like URL variable
http.open('get', 'updateit.php?gpe='+gpe+'&gpm=' +gpm+'&gpv=' +gpv+'&gpb=' +gpb+'&gpk=' +gpk+'&gpk10=' +gpk10+'&gpg=' +gpg+'&gps=' +gps+'&gpsc=' +gpsc+'&gpep=' +gpep+'&gpRv=' +gpRv+'&gpRb=' +gpRb+'&gpRs=' +gpRs+'&gpRg=' +gpRg+'&gpRt=' +gpRt+'&nocache = '+nocache);
http.onreadystatechange = insertReply;
http.send(null);
}
function insertReply() {
if(http.readyState == 4){
var response = http.responseText;
// else if login is ok show a message: "Site added+ site URL".
document.getElementById('insert_response').innerHTML = ''+response;
}
}

(我听说你也可以更容易地通过 jQuery,但我从来没有弄清楚,所以我会在另一个问题上解决这个问题,所以请不要提醒我。)

谢谢!

最佳答案

你混合了 GET 和 POST

关于php - undefined index 传递变量与 javascript 到 php,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2284633/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com