-1

我使用 oop 和 mysql 在 php 中具有此功能,有人可以告诉我代码中的错误是什么,我对 oop 完全陌生,

private function add_img($whichimg) {

    $query = mysql_query("SELECT max(gallery_id) as maxi FROM gallery") or die(mysql_error());
    $row = mysql_fetch_assoc($query);
    $this->maximum = $row["maxi"];

    $add_to_db = $this->query("INSERT INTO gallery (title,gallery_id) VALUES('$whichimg','$this->maximum')") or die(mysql_error());
    return $add_to_db;
}
4

1 回答 1

1

错误在这里:'$this->maximum'

$this->query("INSERT INTO gallery (title,gallery_id) VALUES('$whichimg','".$this->maximum."')") or die(mysql_error());

或者

$this->query("INSERT INTO gallery (title,gallery_id) VALUES('$whichimg','{$this->maximum}')") or die(mysql_error());

甚至更好

$sql = sprintf("INSERT INTO gallery (title,gallery_id) VALUES('%s','%s')", $whichimg, $this->maximum); $this->query($sql) 或 die(mysql_error());

于 2012-07-12T15:07:10.960 回答