我正在从注册表中收集数据,其中一个字段是外键。外键是(tru id),这是我正在使用的代码。这里的问题是我得到了由tru id引起的一般错误。
这是我的表的架构:
CREATE TABLE kfupm_tournament (
tr_id numeric NOT NULL,
tr_name character varying(40) NOT NULL,
start_date date NOT NULL,
end_date date NOT NULL,
PRIMARY KEY (tr_id) );
CREATE TABLE kfupm_team (
team_id numeric NOT NULL,
tr_id numeric NOT NULL,
team_group character(1) NOT NULL,
PRIMARY KEY (team_id, tr_id),
FOREIGN KEY (tr_id) REFERENCES kfupm_tournament (tr_id));
我想问题是因为我正在插入tru id,因为它是本地密钥。
<?php
$conn = mysqli_connect("localhost", "root", "", "ICS324");
// Check connection
if($conn === false){
die("ERROR: Could not connect. "
. mysqli_connect_error());
}
$tr_id = $_REQUEST['tr_id'];
$team_id = $_REQUEST['team_id'];
$team_group = $_REQUEST['team_group'];
// here is the problem
$sql = "INSERT INTO kfupm_team VALUES ('$tr_id',
'$team_id','$team_group')" ;
if(mysqli_query($conn, $sql)){
echo "<h3>data stored in a database successfully."
. " Please browse your localhost php my admin"
. " to view the updated data</h3>";
echo nl2br("\n$tr_id\n $tr_name\n "
. "$start_date\n $end_date");
}
?>
暂无答案!
目前还没有任何答案,快来回答吧!