ghadirkiani
یک شنبه 14 دی 1393, 23:55 عصر
سلام
من تو php تازه کارم و دارم تمرین میکنم
من یه دیتابیس ساختم و درونش یه جدول که دارای سه فیلد id title content هستش
میخوام توش مطلب ذخیره کنم
حالا یه کلاس براش نوشتم که کد زیر هستش
میشه بگید چه مشکلی داره که کار نمیکنه؟ هیچ اروری هم نمیده
<?phpinclude 'config1.php';
$title=$_POST['title'];
$content=$_POST['content'];
class zahra{
private $host;
private $root;
private $pass;
private $db;
private $title;
private $content;
function __construct() {
global $host;
global $root;
global $pass;
global $db;
global $title;
global $content;
$this->host = $host;
$this->root = $root;
$this->pass = $pass;
$this->db = $db;
$this->title = $title;
$this->content = $content;
}
/*------------------------------------------------------------------------------------*/
public function connect() {
mysql_connect($this->host,$this->root,$this->pass);
mysql_select_db($this->db);
}
/*------------------------------------------------------------------------------------*/
public function getnewsid(){
$this->connect();
$id = 0;
$result = mysql_query("SELECT * FROM `ghadir` ORDER BY `id` DESC LIMIT 1 ");
if (mysql_num_rows($result) > 0) {
$id = mysql_result($result,0,0);
} $id++;
return $id;}
/*------------------------------------------------------------------------------------*/
public function insertcontent($title,$content){
$this->connect();
$id = $this->getnewsid();
$result = mysql_query("INSERT INTO `ghadir` VALUES ('$id',$this->title','$this->content')");
return mysql_affected_rows();}
/*------------------------------------------------------------------------------------*/
}
$obja = new zahra;
$obja->insertcontent($title,$content);
?>
من تو php تازه کارم و دارم تمرین میکنم
من یه دیتابیس ساختم و درونش یه جدول که دارای سه فیلد id title content هستش
میخوام توش مطلب ذخیره کنم
حالا یه کلاس براش نوشتم که کد زیر هستش
میشه بگید چه مشکلی داره که کار نمیکنه؟ هیچ اروری هم نمیده
<?phpinclude 'config1.php';
$title=$_POST['title'];
$content=$_POST['content'];
class zahra{
private $host;
private $root;
private $pass;
private $db;
private $title;
private $content;
function __construct() {
global $host;
global $root;
global $pass;
global $db;
global $title;
global $content;
$this->host = $host;
$this->root = $root;
$this->pass = $pass;
$this->db = $db;
$this->title = $title;
$this->content = $content;
}
/*------------------------------------------------------------------------------------*/
public function connect() {
mysql_connect($this->host,$this->root,$this->pass);
mysql_select_db($this->db);
}
/*------------------------------------------------------------------------------------*/
public function getnewsid(){
$this->connect();
$id = 0;
$result = mysql_query("SELECT * FROM `ghadir` ORDER BY `id` DESC LIMIT 1 ");
if (mysql_num_rows($result) > 0) {
$id = mysql_result($result,0,0);
} $id++;
return $id;}
/*------------------------------------------------------------------------------------*/
public function insertcontent($title,$content){
$this->connect();
$id = $this->getnewsid();
$result = mysql_query("INSERT INTO `ghadir` VALUES ('$id',$this->title','$this->content')");
return mysql_affected_rows();}
/*------------------------------------------------------------------------------------*/
}
$obja = new zahra;
$obja->insertcontent($title,$content);
?>