arne2
12-18-2007, 06:08 PM
Below you can see the code i'm using.
I'm using it to send an id number to vote.php. Here this id should be saved in a mysql database. When i go to vote.php?id=3 directly in my browser it saves the id (3) in my mysql database so the vote.php page is totally correct and working.
But for some reasing, when i use the link, it doesn't save the id. I do however get the alert messages that i have voted so there's nothing really wrong with the javascirptcode. Why isn't it saving the id when i click on the link?
<?php include("header.php");?>
<!--AJAX REFRESH (hoho, (c) AdJ )-->
<script language="javascript" type="text/javascript">
<!--
//Browser Support Code
function ajaxFunction(id,lied){
var ajaxRequest;
try{
// Opera 8.0+, Firefox, Safari
ajaxRequest = new XMLHttpRequest();
} catch (e){
// Internet Explorer Browsers
try{
ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try{
ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e){
// Something went wrong
alert("Er is een probleem met (de instellingen van) uw browser, u kan niet stemmen!");
return false;
}
}
}
// Create a function that will receive data sent from the server
ajaxRequest.onreadystatechange = function(){
// if(ajaxRequest.readyState == 4){
// document.myForm.time.value = ajaxRequest.responseText;
// }
}
//var id = document.getElementById('id').value;
this.lied= lied;
this.id= id;
var queryString = "?id=" + id;
ajaxRequest.open("GET", "http://www.webmasterhelp.biz/pilotlight/vote.php" + queryString, true);
ajaxRequest.send(null);
alert('Merci! Je stemde voor ' + lied + '!');
}
//-->
</script>
<!--einde ajaxbedoening en een half uur denkwerk-->
<div style="width:710px; height:554px; overflow:auto;
background-image:url(images/index_r4_c2.gif);"><img src="http://www.webmasterhelp.biz/pilotlight/Titles/Home%20Title.gif">
<?php
$act=$_GET['act'];
//DB Connectie
$host = "localhost";
$user = "x";
$pass = "x";
$db = "x";
mysql_connect($host,$user,$pass) or die(mysql_error());
mysql_select_db($db);
$query = mysql_query("Select lied,artiest,id From proposals WHERE approved='1' ORDER BY ID DESC");
?>
<p align="left"><u>De ingestuurde voorstellen!</u>
<br><br>Hieronder staan alle liedjes die zijn voorgesteld op onze site. De uitzonderlijk schrale, grappige en ondoenbare voorstellen hebben we hier wel al uit geschrapt. Dit wil natuurlijk niet zeggen dat we ze ook echt spelen. Als je toch heel graag een nummer van de lijst door ons gecoverd ziet, kan je op het liedje klikken! Zo weten wij wat jullie graag zouden horen...<br>
<br>
<table width="90%" border="1" bordercolor="#3D515A">
<tr bgcolor="#047391">
<td width="35%"><b>Artiest</b></td>
<td><b>Lied</b></td>
</tr>
<?
$color1="#38464C";
$color2="#1E2C32";
$i=1;
while($obj = mysql_fetch_object($query)){
if($i=='1'){
$c="$color2";
}else{
$c="$color1";
}?>
<tr bgcolor="<?php echo"$c";?>">
<td width="35%"><?php echo " $obj->artiest"; ?></td>
<td><A style="text-decoration: none;" HREF="#" onClick="ajaxFunction(<?php echo"$obj->id";?>,'<?php echo"$obj->lied";?>')"> <?php echo " $obj->lied"; ?></a></td>
</tr>
<?php
if($i=='2'){$i=0;} //I RESETTEN}
$i++;
}?>
</table>
</p>
</div>
<?php include("footer.php");?>
I'm using it to send an id number to vote.php. Here this id should be saved in a mysql database. When i go to vote.php?id=3 directly in my browser it saves the id (3) in my mysql database so the vote.php page is totally correct and working.
But for some reasing, when i use the link, it doesn't save the id. I do however get the alert messages that i have voted so there's nothing really wrong with the javascirptcode. Why isn't it saving the id when i click on the link?
<?php include("header.php");?>
<!--AJAX REFRESH (hoho, (c) AdJ )-->
<script language="javascript" type="text/javascript">
<!--
//Browser Support Code
function ajaxFunction(id,lied){
var ajaxRequest;
try{
// Opera 8.0+, Firefox, Safari
ajaxRequest = new XMLHttpRequest();
} catch (e){
// Internet Explorer Browsers
try{
ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try{
ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e){
// Something went wrong
alert("Er is een probleem met (de instellingen van) uw browser, u kan niet stemmen!");
return false;
}
}
}
// Create a function that will receive data sent from the server
ajaxRequest.onreadystatechange = function(){
// if(ajaxRequest.readyState == 4){
// document.myForm.time.value = ajaxRequest.responseText;
// }
}
//var id = document.getElementById('id').value;
this.lied= lied;
this.id= id;
var queryString = "?id=" + id;
ajaxRequest.open("GET", "http://www.webmasterhelp.biz/pilotlight/vote.php" + queryString, true);
ajaxRequest.send(null);
alert('Merci! Je stemde voor ' + lied + '!');
}
//-->
</script>
<!--einde ajaxbedoening en een half uur denkwerk-->
<div style="width:710px; height:554px; overflow:auto;
background-image:url(images/index_r4_c2.gif);"><img src="http://www.webmasterhelp.biz/pilotlight/Titles/Home%20Title.gif">
<?php
$act=$_GET['act'];
//DB Connectie
$host = "localhost";
$user = "x";
$pass = "x";
$db = "x";
mysql_connect($host,$user,$pass) or die(mysql_error());
mysql_select_db($db);
$query = mysql_query("Select lied,artiest,id From proposals WHERE approved='1' ORDER BY ID DESC");
?>
<p align="left"><u>De ingestuurde voorstellen!</u>
<br><br>Hieronder staan alle liedjes die zijn voorgesteld op onze site. De uitzonderlijk schrale, grappige en ondoenbare voorstellen hebben we hier wel al uit geschrapt. Dit wil natuurlijk niet zeggen dat we ze ook echt spelen. Als je toch heel graag een nummer van de lijst door ons gecoverd ziet, kan je op het liedje klikken! Zo weten wij wat jullie graag zouden horen...<br>
<br>
<table width="90%" border="1" bordercolor="#3D515A">
<tr bgcolor="#047391">
<td width="35%"><b>Artiest</b></td>
<td><b>Lied</b></td>
</tr>
<?
$color1="#38464C";
$color2="#1E2C32";
$i=1;
while($obj = mysql_fetch_object($query)){
if($i=='1'){
$c="$color2";
}else{
$c="$color1";
}?>
<tr bgcolor="<?php echo"$c";?>">
<td width="35%"><?php echo " $obj->artiest"; ?></td>
<td><A style="text-decoration: none;" HREF="#" onClick="ajaxFunction(<?php echo"$obj->id";?>,'<?php echo"$obj->lied";?>')"> <?php echo " $obj->lied"; ?></a></td>
</tr>
<?php
if($i=='2'){$i=0;} //I RESETTEN}
$i++;
}?>
</table>
</p>
</div>
<?php include("footer.php");?>