0

For some reason this ajax call sends data to the php file fine, and the MYSQL call works, but the php does not return anything to the ajax. I'm not sure if it's an issue with the ajax call or the php (I suspect the former). Could it have something to do with var 'data'? Is it the 'return false'? Or have I just stared at for too long and am missing something extremely simple?

It's weird because I've written this type of call a hundred times. Any help would be appreciated.


The jQuery:

$("#registration").submit(function (){
	
		var newun = $("#newusername").val();
 		var newpass = $("#pass1").val();
		var email = $("#email").val();
		var sques = $("#secquestion").val();
		var sans = $("#secanswer").val();
			
		$.ajax ({
			url: "include/registerfinalize.php",
			data: {"newun": newun,
				"newpass": newpass,
				"email": email,
				"sques": sques,
				"sans": sans},
			success: function (data){
	
				alert(data)
		
			}
			
		})
		
		return false
		
	})

The PHP (simplified - it'll do more later):

<?php

include("../../bin/cxn.inc");

$cxn = mysqli_connect($host, $user, $pw, $db) or die ("Connection failed.");

	$newuser = mysqli_real_escape_string($cxn, $_GET['newun']);
	$newpass = mysqli_real_escape_string($cxn, $_GET['newpass']);
	$email = mysqli_real_escape_string($cxn, $_GET['email']);
	$sques = mysqli_real_escape_string($cxn, $_GET['sques']);
	$sans = mysqli_real_escape_string($cxn, $_GET['sans']);

	$query = "INSERT INTO whatever (username, password, blurb, achievements, sequence, favorites, remember, email, secquestion, secanswer) VALUES ('$newuser', '$newpass', '', '', '', '', '', '$email', '$sques', '$sans')";
	$result = mysqli_query($cxn, $query) or die("database connection error");
	

echo "1";

mysqli_free_results($cxn);			
mysqli_close($cxn);

?>
1
Contributor
1
Reply
2
Views
5 Years
Discussion Span
Last Post by elbeato
0

Well, bash you head against a problem long enough, and eventually you'll solve it.

The problem was an innocuous but nasty little line in the PHP. Can you spot it?

mysqli_free_results($cxn);

should be

mysqli_free_result($cxn);

Because of the typo, the php was connecting to the database and inserting the data but not finishing the script and closing the connection. As a result, the Ajax call wasn't getting any success or failure response, and so it was happy to keep waiting. Forever.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.