Php 关于传递给查询的变量的问题 函数add\u new($father=0,$chName,$desc,$icon)//添加新类别 { $position=$this->get_position($father); $sql=“插入到“$this->table_name.”(位置、c_名称、c_描述、c_图标、c_组) 值(“”,“$chName.”,“$desc.”,“$icon.”,“$this->Group.”); mysql\u查询($sql)或死亡(触发\u错误(“mysql错误:”。mysql\u错误()。“使用的查询:”。信息:”,E\u用户错误)); $sql=“更新”。$this->table\u name。“ 设置位置=“$father” 其中id=”.mysql_insert_id()。“”; mysql\u查询($sql)或死亡(触发\u错误(“mysql错误:”。mysql\u错误()。“使用的查询:”。信息:”,E\u用户错误)); }

Php 关于传递给查询的变量的问题 函数add\u new($father=0,$chName,$desc,$icon)//添加新类别 { $position=$this->get_position($father); $sql=“插入到“$this->table_name.”(位置、c_名称、c_描述、c_图标、c_组) 值(“”,“$chName.”,“$desc.”,“$icon.”,“$this->Group.”); mysql\u查询($sql)或死亡(触发\u错误(“mysql错误:”。mysql\u错误()。“使用的查询:”。信息:”,E\u用户错误)); $sql=“更新”。$this->table\u name。“ 设置位置=“$father” 其中id=”.mysql_insert_id()。“”; mysql\u查询($sql)或死亡(触发\u错误(“mysql错误:”。mysql\u错误()。“使用的查询:”。信息:”,E\u用户错误)); },php,mysql,Php,Mysql,现在我的问题是为什么更新查询Through works不接受父变量。我不确定它是否适用。我认为具有默认值的变量应该放在参数列表的末尾 function add_new($father = 0 , $chName, $desc , $icon ) // add new category { $position = $this->get_position($father); $sql = "INSERT into ".$this->table_name."(position,c_n

现在我的问题是为什么更新查询Through works不接受父变量。我不确定它是否适用。

我认为具有默认值的变量应该放在参数列表的末尾

function add_new($father = 0 , $chName, $desc , $icon )  // add new category
{

$position  = $this->get_position($father);
$sql = "INSERT into ".$this->table_name."(position,c_name,c_desc,c_icon,c_group)
        VALUES('','".$chName."','".$desc."','".$icon."','".$this->Group."')";

mysql_query($sql) or die(trigger_error("<br><storng><u>MySQL Error:</u></strong><br>".mysql_error()."<br><br><storng><u>Query Used:</u></strong><br>".$sql."<br><br><storng><u>Info:</u></strong><br>",E_USER_ERROR));

$sql = "UPDATE ".$this->table_name."
        SET position = '$father'
        WHERE id = '".mysql_insert_id()."'";

mysql_query($sql) or die(trigger_error("<br><storng><u>MySQL Error:</u></strong><br>".mysql_error()."<br><br><storng><u>Query Used:</u></strong><br>".$sql."<br><br><storng><u>Info:</u></strong><br>",E_USER_ERROR));

}
请注意,使用默认参数时,任何默认值都应位于任何非默认参数的右侧;否则,事情将无法按预期进行


我认为具有默认值的变量应该放在参数列表的末尾

function add_new($father = 0 , $chName, $desc , $icon )  // add new category
{

$position  = $this->get_position($father);
$sql = "INSERT into ".$this->table_name."(position,c_name,c_desc,c_icon,c_group)
        VALUES('','".$chName."','".$desc."','".$icon."','".$this->Group."')";

mysql_query($sql) or die(trigger_error("<br><storng><u>MySQL Error:</u></strong><br>".mysql_error()."<br><br><storng><u>Query Used:</u></strong><br>".$sql."<br><br><storng><u>Info:</u></strong><br>",E_USER_ERROR));

$sql = "UPDATE ".$this->table_name."
        SET position = '$father'
        WHERE id = '".mysql_insert_id()."'";

mysql_query($sql) or die(trigger_error("<br><storng><u>MySQL Error:</u></strong><br>".mysql_error()."<br><br><storng><u>Query Used:</u></strong><br>".$sql."<br><br><storng><u>Info:</u></strong><br>",E_USER_ERROR));

}
请注意,使用默认参数时,任何默认值都应位于任何非默认参数的右侧;否则,事情将无法按预期进行


您没有使用
$position
变量-我不明白您为什么要执行两个查询:

function add_new($var1, $var2, $father = 0) { /*...*/ }

另外,默认参数仅在参数列表的末尾才有意义。

您没有使用
$position
变量-我不明白您为什么要执行两个查询:

function add_new($var1, $var2, $father = 0) { /*...*/ }

此外,默认参数仅在参数列表的末尾才有意义。

您拼错了。我情不自禁地注意到一些小事;pNo wonder PHP因SQL注入攻击而受到如此恶劣的指责。看看
mysql\u real\u escape\u string()
…@gahooa是的,这都要感谢神奇的引号。(叹气)你拼错了。我情不自禁地注意到一些小事;pNo wonder PHP因SQL注入攻击而受到如此恶劣的指责。看看
mysql\u real\u escape\u string()
…@gahooa是的,这都要感谢神奇的引号。(叹气)