首先要求您输入您的姓名,密码和电子邮件,当您单击“提交”时,它会将您带到另一个页面(ChooseDepartment.PHP),在该页面中,您可以从我的数据库中获取所有部门的列表以选择您自己的部门.
现在,我是一个新手,所以这里是我在SELECTDepartment.PHP中遇到的PHP代码的一部分:
$ShowPossibleDep = MysqL_query("SELECT name,DEPT_ID FROM DEPARTMENT");if(MysqL_num_rows($ShowPossibleDep) > 0){ echo "<br />"."Available departments: "." ".MysqL_num_rows($ShowPossibleDep)."<br />"; echo "<br />"; echo '<form ID = "dept" action = "Courses.PHP" method = "post">'; while($row = MysqL_fetch_array($ShowPossibleDep)) { echo $row['name']; echo '<input type="radio" name="department" value=<?PHP $row['DEPT_ID'] ?>>'; echo "<br />"; } echo '<input type = "submit" value = "submit" ID = "submitDepartment">'; echo </form>;}
我试图让单选按钮的值携带的值
部门ID,所以我可以用学生的部门更新我的数据库,该部门当前为NulL,但我无法弄清楚如何在同一行正确使用HTML和PHP!这给了我语法错误!
你得到语法错误的原因只是因为你没有正确地 *** 作字符串.
错误是这一行
echo '<input type="radio" name="department" value=<?PHP $row['DEPT_ID'] ?>>'; ^ here ^ here
因此,您需要删除PHP标记,并需要正确连接字符串,如:
echo '<input type="radio" name="department" value="'.$row['DEPT_ID']. '">';
和这一个
echo </form>;
你在表格标签周围缺少引号.应该如此,
echo '</form>';
还有其他一些拼写错误,所以你的最终代码将是这样的.
$ShowPossibleDep = MysqL_query("SELECT name,DEPT_ID FROM DEPARTMENT");if(MysqL_num_rows($ShowPossibleDep) > 0){ echo "<br />Available departments: ".MysqL_num_rows($ShowPossibleDep); //echo "<br />"; add this <br /> tag to next echo echo '<br /><form ID = "dept" action = "Courses.PHP" method = "post">'; while($row = MysqL_fetch_array($ShowPossibleDep)) { echo $row['name']; echo '<input type="radio" name="department" value=" '.$row['DEPT_ID'].'"><br />'; //or you can do this way //echo "<input type='radio' name='department' value='$row[DEPT_ID]'><br />"; //echo "<br />"; appended in upper statement. } echo '<input type = "submit" value = "submit" ID = "submitDepartment"></form>'; //echo </form>; closed already(above statement).}
没有评论,更清洁:)
$ShowPossibleDep = MysqL_query("SELECT name,DEPT_ID FROM DEPARTMENT");if(MysqL_num_rows($ShowPossibleDep) > 0){ echo "<br />Available departments: ".MysqL_num_rows($ShowPossibleDep); echo '<br /><form ID = "dept" action = "Courses.PHP" method = "post">'; while($row = MysqL_fetch_array($ShowPossibleDep)) { echo $row['name']; echo '<input type="radio" name="department" value=" '.$row['DEPT_ID'].'"><br />'; } echo '<input type = "submit" value = "submit" ID = "submitDepartment"></form>';}总结
以上是内存溢出为你收集整理的HTML代码中的PHP变量全部内容,希望文章能够帮你解决HTML代码中的PHP变量所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)