[英]PHP mySQL, inserting content into two tables
Trying to insert into two database tables with one try! 尝试一次插入两个数据库表!
$query = "INSERT INTO category
(base_img) VALUES ('$imgsrc')";
$insert_row = $db->insert($query);
//Getting last ID
$catID = mysql_insert_id();
$query = "INSERT INTO cat_lng
(locate, foreign_id, name, body) VALUES
('lv', '$catID', '$name_lv', '$text_lv'),
('ru', '$catID', '$name_ru', '$text_ru'),
('en', '$catID', '$name_en', '$text_en')";
$insert_row = $db->insert($query);
My insert function: 我的插入功能:
public function insert($query){
$insert_row = $this->link->query($query) or die($this->link->error.__LINE__);
//Validate Insert
if($insert_row){
header("Location: index.php?msg=".urlencode('Record Added'));
exit();
} else {
die('Error : ('. $this->link->errno .') '. $this->link->error);
}
}
Code inserts into category, but stops after that! 代码插入到类别中,但此后停止! Cant figure out why..?
不能找出原因..? They work seperatly but cant get them working together!
他们分开工作,但不能让他们一起工作!
Hello: The exit() functions terminates the execution of the script. 您好:exit()函数终止脚本的执行。
http://php.net/manual/en/function.exit.php http://php.net/manual/zh/function.exit.php
You might change: 您可能会更改:
exit()
to 至
return true;
Change the name of $query as $query1 and $insert_row as $insert_row1 which will insert $query1 or any other name you like to use than use the if as follow: 将$ query的名称更改为$ query1,将$ insert_row的更改为$ insert_row1,这将插入$ query1或您想要使用的其他任何名称,而不是使用if,如下所示:
if($insertrow && $insertrow1)
{
//bunch of code here
}
And also you can use mysqli_muti_query function for one name. 而且,您也可以将mysqli_muti_query函数用于一个名称。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.