求助!关于数据库的插入问题,请高手帮忙看看!
小弟正在做一个网站,但有一个数据库的插入问题一直没有解决。
我的数据库可以调用,但是不能插入新的记录,所以请高手帮我看一下:
<?php require_once('Connections/napier.php'); ?>
<?php
$country = $_REQUEST['country'];
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
\\可能是下面的编码有问题
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO `$country` (qualification, work_experence_required) VALUES (%s, %s)",
GetSQLValueString($_POST['qualification'], "text"),
GetSQLValueString($_POST['w_experence'], "int"));
mysql_select_db($database_napier, $napier);
$Result1 = mysql_query($insertSQL, $napier) or die(mysql_error());
$insertGoTo = "editcertificate.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
mysql_select_db($database_napier, $napier);
$query_certificate = "SELECT * FROM `$country`";
$certificate = mysql_query($query_certificate, $napier) or die(mysql_error());
$row_certificate = mysql_fetch_assoc($certificate);
$totalRows_certificate = mysql_num_rows($certificate);
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>Add</title>
</head>
<body>
<form name="form1" method="POST" action="<?php echo $editFormAction; ?>">
Country:
<input name="addcountry" type="text" id="addcountry" value="<?php echo "$country"; ?>">
<p>Qualification:
<input name="qualification" type="text" id="qualification">
</p>
<p>Work Experence Required:
<input name="w_experence" type="text" id="w_experence">
</p>
<p>
<input name="add" type="submit" id="add" value="Add">
<input type="hidden" name="MM_insert" value="form1">
</p>
</form>
</body>
</html>
<?php
mysql_free_result($certificate);
?>
这页是从上页读取了$country,然后在这页调用数据库,然后插入新的记录。
每次我点击“add”按钮就会出现以下错误信息:
Incorrect table name '' (这里是两个单引号)
我用的是DREAMWEAVER
请大家一起看看,谢谢!