1

I am making an "updating" pages with JS jquery..

But in my updateit.php i just get Undefined index on all my fields. I dont know why.

Here's the form:

<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>

updateit.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";
?>

(i know my variables in PHP isnt safe, but im just testing..)

and the script:

/* ---------------------------- */
/* 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;
}
} 

(ive heard you can pass with jQuery much easier too, but i never figured it out, so i will take that on another question, so please dont remind me.)

Thank you!

1 Answer 1

2

You have mixed GET vs POST

Sign up to request clarification or add additional context in comments.

2 Comments

Cant find where ive mixeed it? besides the http.open(get) but i changed to post
Sending via post is slightly different. See this openjs.com/articles/ajax_xmlhttp_using_post.php also, study the difference between encodeuri and encodeuricomponent. You want encodeuricomponent in this case.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.