PHP函数变量传递

时间:2012-07-22 20:34:29

标签: php sql

生锈,只是简单地试图通过参数传递东西。我究竟做错了什么?

//Insert into DB
function insert(x,y,z)
mysql_query("INSERT INTO x (y)
VALUES ('z')");


insert("test","name","Tyler");

2 个答案:

答案 0 :(得分:4)

function insert($x,$y,$z){
    mysql_query("INSERT INTO ".$x." (".$y.") VALUES ('".$z."')");
}
insert("test","name","Tyler");

答案 1 :(得分:1)

确保通过$正确引用变量:

//Insert into DB
function insert($x, $y, $z)
{
    mysql_query("INSERT INTO $x ($y) VALUES ('$z')");
}


insert("test","name","Tyler");