[急]請問 appserv 2.4.4a 裡面mysql的問題

請問一下
我做了一個輸入姓名&學號 就可以寫進資料庫的網站

這裡

當資料都打完整之後
按下"送出"

卻出現這樣的訊息

You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '-mail, wretchaccount, msn, yahoo) VALUES ('test', 'andy', '0912


有高手可以指點迷津嗎?感恩~~~
2009-09-11 11:55 發佈
SQL語法有錯誤

我猜錯誤應該來自你的欄位名稱是E-mail

不能有"-"這個特殊字

所以請在欄位前後加個 ' 號

改成 'E-mail'

insert into table('E-mail')values('xxx@ccc.com')

這樣就可以了
penguin0114 wrote:
SQL語法有錯誤我猜...(恕刪)


謝謝您的回答


您是說直接從資料庫把欄位名稱改掉嗎?

我已經改過了
但是還是一樣的訊息呢~


囧a

請問還有其他方法嗎?

小橘子很酸唷>W<* wrote:


謝謝您的回答

...(恕刪)


請把您的mySQL insert的語法貼出來吧
<?php
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 pcman (studentnumber, name, phone, wretchaccount, msn, yahoo) VALUES (%s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['nu'], "text"),
GetSQLValueString($_POST['studentname'], "text"),
GetSQLValueString($_POST['phone'], "text"),
GetSQLValueString($_POST['email'], "text"),
GetSQLValueString($_POST['wr'], "text"),
GetSQLValueString($_POST['msn'], "text"));


mysql_select_db($database_student, $student);
$Result1 = mysql_query($insertSQL, $student) or die(mysql_error());

$insertGoTo = "/classmate/thanks.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
?>


PS: 我在猜想 是不是if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO pcman (studentnumber, name, phone, wretchaccount, msn, yahoo) VALUES (%s, %s, %s, %s, %s, %s)"
這段phone,的後面少了一個email


然後多加了email之後變這樣if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO pcman (studentnumber, name, phone, email, wretchaccount, msn, yahoo) VALUES (%s, %s, %s, %s, %s, %s)",
但是發現它出現另一種錯誤訊息 Orz 訊息如下:Column count doesn't match value count at row 1

PS: 我在猜想 是不是if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO pcman (studentnumber, name, phone, wretchaccount, msn, yahoo) VALUES (%s, %s, %s, %s, %s, %s)"這段phone,的後面少了一個email

加單引號呢?
INSERT INTO pcman (studentnumber, name, phone, wretchaccount, msn, yahoo) VALUES ('%s', '%s', '%s', '%s', '%s', '%s')


然後多加了email之後變這樣if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO pcman (studentnumber, name, phone, email, wretchaccount, msn, yahoo) VALUES (%s, %s, %s, %s, %s, %s)",但是發現它出現另一種錯誤訊息 Orz 訊息如下:Column count doesn't match value count at row 1

少一個 %s

我不會 PHP 亂猜…你試試看行不行
抓狂一族 wrote:
PS: 我在猜想 是...(恕刪)



喔喔
我加了
少一個%s

但是後來出現這訊息= =

Warning: Cannot modify header information - headers already sent by (output started at c:\appserv\www\classmate\ifo.php:1) in c:\appserv\www\classmate\ifo.php on line 51


第51行(也就是最後一行)我的程式碼是這個
我是用dreamweaver做的

header(sprintf("Location: %s", $insertGoTo));
}
內文搜尋
X
評分
評分
複製連結
Mobile01提醒您
您目前瀏覽的是行動版網頁
是否切換到電腦版網頁呢?