这是我试图插入MYSQL中的表的查询
$query1 = "SELECT close FROM stocks WHERE the_date = '$the_date' AND ticker = '$ticker' ";
$result1 = mysql_query($query1) or die("Query failed : " . mysql_error());
我设法将它打印出来:
while($price = mysql_fetch_assoc($result1)){
echo "Price: ".$price['close']."<br /></h2>";
}
我试着用这个插入:
$query3 = "INSERT INTO transactions (trans_ID,the_date,client_ID,ticker,shares,price,buy)
VALUES (\"$trans_ID\",\"$the_date\",client_ID,\"$ticker\",
$shares,$price,$buy)";
但页面上的错误消息说: “查询失败:您的SQL语法出错;请查看与您的MySQL服务器版本对应的手册,以便在第3行使用'1'附近的正确语法”,这很奇怪,因为这就是我的html / head标签的位置是
所以我试着这样做:
var_dump($price);
得到了这个:bool(假)
所以我怎么做它所以我可以插入$ price? 我查了一些关于插入数组,内爆,序列化的东西,但我似乎无法让它工作?
谢谢!
答案 0 :(得分:0)
您的查询应该像
$query3 = "INSERT INTO transactions (trans_ID,the_date,client_ID,ticker,shares,price,buy)
VALUES ('$trans_ID','$the_date','$client_ID','$ticker',
'$shares','$price','$buy')";
但也不要忘记在查询中对所有这些变量使用mysql_real_escape_string
。