I am trying to connect with myqli trought a ajax call. cause i am testing the database input of the user.
The script is crashing at: $testBase = new mysqli("sfd", "sdf", "sdg", "sdf");
And in the console stands: Uncaught SyntaxError: Unexpected token <
Yes u searched this question but by most people you'll get that error when you do a query and mine is doing that already when i try to create a mysqli connection.
Ajax script:
if (error == false){
var name = $('#name').val(),
url = $('#url').val(),
datahost = $('#datahost').val(),
datausername = $('#datausername').val(),
datapassword = $('#datapassword').val(),
dataname = $('#dataname').val(),
license = $('#license').val(),
data = 'name='+ name +'&url='+ url +'&datahost='+ datahost +'&datausername='+ datausername +'&datapassword='+ datapassword +'&dataname='+ dataname +'&license='+ license;
$( "#trans" ).fadeIn( 500, function() {
$.ajax({
type: "POST",
url: "handlers/install.php",
data: data,
success: function(e){ // this happen after we get result
react(e);
}
});
});
}
please help me
The response of handelers/install.php is:
"<br />
<b>Warning</b>: mysqli::mysqli(): (HY000/1130): Host 'server2.ughost.nl' is not allowed to connect to this MySQL server in <b>/home/universa/public_html/klant/handlers/install.php</b> on line <b>59</b><br />
<br />
<b>Warning</b>: mysqli::close(): Couldn't fetch mysqli in <b>/home/universa/public_html/klant/handlers/install.php</b> on line <b>75</b><br />
{\"ban\":0,\"error\":0,\"license\":0,\"url\":0,\"name\":0,\"sql\":0,\"message\":\"localhost + asd + asdas+dasf\"}"
Ok the problem was that the install.php always give a warning when the login is incorrect. But i needed to check it because this is a users input so how did i fix it?
error_reporting(0);
$testBase = new mysqli($datahost, $datausername, $datapassword, $dataname);
error_reporting(1);
if ($testBase->connect_errno) {
$response['sql'] = 1;
$testBase->close();
} else {
//can connect with database
$testBase->close();
}