PHP外键问题提交新数据
我试图创建一个页面,当用户在其博客文章上单击submit时,它会将其发布到预先存在的数据库表中。我经常遇到的错误是,我没有正确地从博客文章到博客表引用表id(tid)。我认为,如果我将单选按钮的值更改为相应的表id值,并使用它们进行一些循环,它将起作用,但我仍然不确定如何引用它。我真的被困在这一点上了。非常感谢您的帮助 以下是我的单选按钮,用于选择要查看的表: first.phpPHP外键问题提交新数据,php,mysql,Php,Mysql,我试图创建一个页面,当用户在其博客文章上单击submit时,它会将其发布到预先存在的数据库表中。我经常遇到的错误是,我没有正确地从博客文章到博客表引用表id(tid)。我认为,如果我将单选按钮的值更改为相应的表id值,并使用它们进行一些循环,它将起作用,但我仍然不确定如何引用它。我真的被困在这一点上了。非常感谢您的帮助 以下是我的单选按钮,用于选择要查看的表: first.php <form name ="myForm" action ="second.php<?php echo h
<form name ="myForm" action ="second.php<?php echo htmlspecialchars($_SERVER['PHP_SELF']);?>" method = "POST">
<h3> Guitar Blog Topics </h3><br>
<input type ="radio" name = "radio1" value ="Topic1" /> Topic1 <br>
<input type ="radio" name ="radio1" value ="Topic2" /> Topic2 <br>
<input type ="radio" name = "radio1" value ="Topic3" /> Topic3 <br>
<input type = "submit" value = "Select"/>
</form>
您的列列表与值列表不匹配,因此您试图输入不存在的内容。试一试
$tid = 'my table id'; // if the datatype of the tid column is varchar
$tid = 3456; // if the datatype of the tid column is int
$tid = $_POST[tid];// make sure when using the $_POST variable that the value matches the datatype
$sql = mysqli_query($dbconnect, "INSERT INTO blog_posts (pid, author, title, post, tid) VALUES (NULL, '$_POST[author]', '$_POST[title]', '$_POST[post]', $tid)")
这就是我所想的,但是通过改变单选按钮的值来对应tid值。如果我能像$tid=$\u POST[radio1].value这样做,我只是对语法感到困惑;
$tid = 'my table id'; // if the datatype of the tid column is varchar
$tid = 3456; // if the datatype of the tid column is int
$tid = $_POST[tid];// make sure when using the $_POST variable that the value matches the datatype
$sql = mysqli_query($dbconnect, "INSERT INTO blog_posts (pid, author, title, post, tid) VALUES (NULL, '$_POST[author]', '$_POST[title]', '$_POST[post]', $tid)")