我正在使用flex builder 3使用php插入到mysql数据库中,一切都在我的localhost中完美运行,问题是当我在Web服务器中部署项目并运行它时,它连接到数据库但是我可以' t插入数据(当我插入数据时它没有显示)
另一个愚蠢的事情是在另一段代码中检索(选择)在我的本地主机和Web服务器上运行良好的数据。
这是php代码:
<?php
$host = "******";
$user = "******";
$pass = "******";
$database = "******";
$linkID = mysql_connect($host, $user, $pass) or die("Could not connect to host.");
mysql_select_db($database, $linkID) or die("Could not find database.");
$nickname = $_POST['nickname'];
$steam = $_POST['steam'];
$c1 = $_POST['c1'];
$c2 = $_POST['c2'];
$c3 = $_POST['c3'];
$results = mysql_query("INSERT INTO `phantom`.`members` (`TF2_Nickname` ,`Steam_User_Name`,
`class1` ,`class2` ,`class3` ,`time`) VALUES ($nickname, $steam, $c1, $c2, $c3,NOW())");
?>
答案 0 :(得分:1)
您还需要declare the values as strings in your MySQL query:
"INSERT INTO `phantom`.`members` (`TF2_Nickname`, `Steam_User_Name`, `class1`, `class2`, `class3`, `time`)
VALUES ('$nickname', '$steam', '$c1', '$c2', '$c3', NOW())"
您还应该以某种方式准备它们,以避免将它们错误地视为SQL命令(请参阅SQL Injection)。 PHP有mysql_real_escape_string
function来做到这一点:
"INSERT INTO `phantom`.`members` (`TF2_Nickname`, `Steam_User_Name`, `class1`, `class2`, `class3`, `time`)
VALUES ('".mysql_real_escape_string($nickname)."', '".mysql_real_escape_string($steam)."', '".mysql_real_escape_string($c1)."', '".mysql_real_escape_string($c2)."', '".mysql_real_escape_string($c3)."', NOW())"