dsgsdg206050 2015-07-21 18:41
浏览 28

用Ajax和php创建表

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?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
    • ¥20 怎么用dlib库的算法识别小麦病虫害
    • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
    • ¥15 java写代码遇到问题,求帮助
    • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
    • ¥15 有了解d3和topogram.js库的吗?有偿请教
    • ¥100 任意维数的K均值聚类
    • ¥15 stamps做sbas-insar,时序沉降图怎么画
    • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
    • ¥15 关于#Java#的问题,如何解决?