I have the following html code in one file:
<html>
<head>
<script>
function showUser(str) {
if (str == "") {
document.getElementById("txtHint").innerHTML = "";
return;
} else {
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
} else {
// code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
document.getElementById("txtHint").innerHTML = xmlhttp.responseText;
}
}
xmlhttp.open("GET","createtable.php?q="+str,true);
xmlhttp.send();
}
}
</script>
</head>
<body>
<form>
<select name="users" onchange="showUser(this.value)">
<option value="">Select a person:</option>
<option value="1">Equipment 1</option>
<option value="2">Equipment 2</option>
<option value="3">Equipment 3</option>
<option value="4">Equipment 4</option>
</select>
</form>
<div id="txtHint"><b>Person info will be listed here...</b></div>
</body>
</html>
My createtable.php code:
<?php
$q = intval($_GET['q']);
$con = mysqli_connect('localhost','root','','results');
if (!$con) {
die('Could not connect: ' . mysqli_error($con));
}
mysqli_select_db($con,"results");
$sql="CREATE TABLE '".$q."'";
$result = mysqli_query($con,$sql);
mysqli_close($con);
?>
When i chose equipment one, a table named 1 is not being created. I think i am wrong near the CREATE TABLE part in createtable.php. How can i fix this?