I am using AJAX to make a "load call" to a PHP script that contains information to be added to a database, the script is as such:
<?php
$create_tables = "
CREATE TABLE IF NOT EXISTS `user` (
`id` int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT,
`name` varchar(255) NOT NULL UNIQUE,
`password` varchar(255) NOT NULL
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=latin1;
CREATE TABLE IF NOT EXISTS `user_details`
(
`id` int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT,
`email_address` varchar(255) NOT NULL UNIQUE,
`address1` varchar(500) NULL,
`address2` varchar(500) NULL,
`address3` varchar(500) NULL,
`postcode` VARCHAR(10) NULL
) ENGINE=InnoDB AUTO_INCREMENT=2 CHARSET=latin1;
INSERT IGNORE INTO `user` (`id`, `name`, `password`) VALUES (1, 'admin', '704b037a97fa9b25522b7c014c300f8a');
INSERT IGNORE INTO `user_details` (`id`, `email_address`) VALUES (1, 'sam.swift@fifteendigital.co.uk');
";
function cre($query)
{
$link = new mysqli();
$link->real_connect("localhost", "root", "", "overr");
return $link->query($query) ? "true" : "false";
}
print cre($create_tables);
?>
And the AJAX is called as thus:
function _ajax( u, t )
{
$.ajax( {
url: u,
type: "GET",
success: function ( r )
{
$( "#test" ).html( r );
console.log( r );
return r;
},
beforeSend: function ()
{
$( t ).html( "Loading" );
}
} );
}
$( document ).ready( function ()
{
_ajax( "aj/tables.php", "#null" );
} );
And when I call the query in phpmyadmin, it works perfect, but when I call it through the AJAX from the load page, the console gets logged "false", how can I make it so that the script executes and returns true, even when there is nothing in the database at all I am still getting "false" returned through to the client.
The purpose of this is to set up the environment before anything is done to ensure that everything is in place and working correctly, this system will change in the future, but for now I just need to get it working