Jump to content

Problems with ajax (not sure but I think it might be ajax causing it)


Snoozy
 Share

Recommended Posts

Now I'm having this strange issue with my website

 

I'm currently working on a tester system and I've encountered a problem that I'm unable to find the issue, tho I'm thinking my ajax php part of the script to be the thing causing it even tho it seems strange that it would cause it.

 

The first part which is connected to where the problem occurs is the echo"<form>"; and from there, It should take you to index.php?page=tester&select=answer, now that is where it in the browser goes there tho it still shows the page stuff from the last page which is index.php?page=tester&select=applications, so it's like showing both &select=answer and &select=applications on the same page.

<?php
$q=$_GET["q"];
include'../config/connection.php';
$result = mysql_query("SELECT * FROM applications WHERE id = '$q'");

echo "<center><table border='1'>
<tr>
<th>Account Name</th>
<th>Character Name</th>
<th>Gender</th>
<th>Skin Color</th>
</tr>";

$row = mysql_fetch_array($result);
  echo "<tr>";
  echo "<td>" . $row['name'] . "</td>";
  echo "<td>" . $row['charactername'] . "</td>";
  echo "<td>" . $row['gender'] . "</td>";
  echo "<td>" . $row['race'] . "</td>";
  echo "</tr></table></center>";
  echo"<br/>";
  echo"<table><tr>
  <th>Description</th>
<th>Metagaming</th>
<th>Powergaming</th></tr>";
echo"<tr>";
  echo "<td><textarea readonly='readonly' style='width:22em; height:20em;'>".$row['description']."</textarea></td>";
  echo "<td><textarea readonly='readonly' style='width:22em; height:20em;'>".$row['mg']."</textarea></td>";
  echo "<td><textarea readonly='readonly' style='width:22em; height:20em;'>".$row['pg']."</textarea></td>";
  echo"</tr></table><table><br/><center><h1>Answer</h1><br/><form action='index.php?page=tester&select=answer' method='post'>";
  echo"<textarea name='why' style='height:10em; width:60em;'></textarea><br/>";
  echo"<input type='submit' name='answer' value='Accept' /><a/>";
  echo"<input type='submit' name='answer' value='Decline' /></center>";
  echo"<input type='hidden' name='id' value='$q'/>";
  echo"</form></table>";
?>

Now on &select=answer it included a page which the script of that include consist of the stuff below, it outputs that the query was successfully, and all that.

<?
if(!empty($_POST['why']))
   {
   $why = mysql_real_escape_string($_POST['why']);
   $answer = trim($_POST['answer']);
   $id = $_POST['id'];
   if($answer == "Accept")
   {
	   $query1 = mysql_query("UPDATE characters SET accepted = '1' WHERE id = '".$id."'");
	   echo"Successfully accepted";
	   $answer = 1; 
   }
   elseif($answer == "Decline")
   {
	   echo"Successfully declined";
	   $answer = 0;
   }
   $query = mysql_query("UPDATE applications SET answer = '$why' AND tester = '".$_COOKIE['Username']."' AND accepted = '$answer' AND answered = '1' WHERE cid = '".$id."'") or die('Could not connect: ' . mysql_error());
   if($query)
   {
	   	echo"<br/>Query went through without problems";
  		header("Refresh: 5;url=index.php?page=tester");
   }
   }
?>

This is the ajax part javascript of it which gets the information for index.php?page=tester&select=applications

<script type="text/javascript">
function showApplication(str)
{
if (str==""||str==0)
{
  	document.getElementById("txtHint").innerHTML="";
  		return;
  	} 
if (window.XMLHttpRequest)
  	{// code for IE7+, Firefox, Chrome, Opera, Safari
  		xmlhttp=new XMLHttpRequest();
  	}
xmlhttp.onreadystatechange=function()
  	{
  	if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    	document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
    }
}
xmlhttp.open("GET","tester/applications.php?q="+str,true);
xmlhttp.send();
}
</script>

If you need any more information feel free to ask for it.

Thanks in advance.

 

 

Link to comment
Share on other sites

This thread is more than a year old.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.