Well it's working, but seemingly there's still something wrong since when I type in a correct name it still comes up as if i'd keyed in a wrong or nonexistent name, so I guess there must be something wrong with my connection...
TO check;
- I put localhost where you put localhost
- 'World' I changed to 'test' as that is my db name
- I put the name of my table in where it said '<yourtable>'
<?php
// retrieve the user name
$name = $_GET['name'];
// generate output depending on the user name received from client
$mysqli = new mysqli("localhost", "", "", "test");
/* check connection */
if ($mysqli->connect_error) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
/* Select queries return a resultset */
if ($result = $mysqli->query("SELECT name FROM raiders")) {
while($obj = $result->fetch_object()){
$userName[]=$obj->name;
}
/* free result set */
$result->close();
}
/* close connection */
$mysqli->close();
//$userNames = array('JAMES', 'BUBBLES', 'SUDOBAAL');
header('Content-Type: text/javascript');
if (in_array(strtoupper($name), $userName))
echo json_encode("1");
else if (trim($name) == '')
echo json_encode("2");
else
echo json_encode("3");
?>
In terms of checking the connection, this definitely does work (it just loads some data from the server);
<?php
$conn = mysql_connect("localhost", "", "");
$name = $_GET['name'];
mysql_select_db("test", $conn);
$sql = "SELECT * FROM raiders where name = '$name' ";
$result = mysql_query($sql, $conn) or die(mysql_error());
while ($newArray = mysql_fetch_array($result)){
$x = $newArray['sl'];
}
header('Content-Type: text/javascript');
echo json_encode($x);
?>
Many thanks,
Jubal