2016-04-22 67 views
-2
$sql = 'INSERT INTO `a1343640_test`.`Orders` 
(`TicketId`, `Id`, `MenuItemName`, `Price`, `Quantity`, `Student ID`, `Student Year`, `Student Name`, `Student Email`) 
    VALUES ('$ticketID', '$orderID ', '$menu', '$price', '$quantity', '$studID', '$StudYr', '$StudName', '$StudEmail');'; 

是我有,但我有一個問題,我不確定我做錯了什麼值。如果有人能幫助我,這將是偉大的。我的sql格式有什麼問題

+0

你忘了'.'例如: '。$ ticketID。','。$ orderID.'' – aldrin27

+1

查看如何連接字符串:http://stackoverflow.com/q/8336858/3933332但請記住,您應該附上用於查詢的引號中的字符串。 – Rizier123

+0

$ sql =「INSERT INTO'a1343640_test'.'Orders' ('TicketId','Id','MenuItemName','Price','Quantity','Student ID','Student Year','Student Name' ,'學生電子郵件') VALUES('$ ticketID','$ orderID','$ menu','$ price','$ quantity','$ studID','$ StudYr','$ StudName',' $ StudEmail')「; – RJParikh

回答

0

您使用引號走錯了路,試試這個

$sql = 'INSERT INTO `a1343640_test`.`Orders` 
(`TicketId`, `Id`, `MenuItemName`, `Price`, `Quantity`, `Student ID`, `Student Year`, `Student Name`, `Student Email`) 
    VALUES ("'.$ticketID.'", "'.$orderID.'", "'.$menu.'", "'.$price.'", "'.$quantity.'", "'.$studID.'", "'.$StudYr.'", "'.$StudName.'", "'.$StudEmail.'");'; 

或另一種方式是

$sql = "INSERT INTO a1343640_test.Orders (TicketId, Id, MenuItemName, Price, Quantity, Student ID, Student Year, Student Name, Student Email) VALUES ('$ticketID', '$orderID ', '$menu', '$price', '$quantity', '$studID', '$StudYr', '$StudName', '$StudEmail')"; 
0

更新查詢:

$sql = 'INSERT INTO `a1343640_test`.`Orders` 
(`TicketId`, `Id`, `MenuItemName`, `Price`, `Quantity`, `Student ID`, `Student Year`, `Student Name`, `Student Email`) 
    VALUES ("'.$ticketID.'", "'.$orderID.'", "'.$menu.'", "'.$price.'", "'.$quantity.'", "'.$studID.'", "'.$StudYr.'", "'.$StudName.'", "'.$StudEmail.'");';