doulu3865 2014-05-16 05:18
浏览 45
已采纳

动态单选按钮错误

Hey guys I'm relatively new to PHP and I've come across an issue with my Syntax I cant seem to fix (I've only started 2-3 weeks ago) and this is my second time trying to generate something 'dynamic generated' from the database.

I'm using radio buttons, so what I'm trying to do is my radio buttons will be generated from my database table and the form which its using will send the information of the value so like 'staffID' to another page to process that info

This is the error I'm getting:

syntax error, unexpected T_STRING, expecting ',' or ';'

I've looked it up it's saying I have some unterminated string of some sort at line 22 which is my echo in my while loop and I'm not too sure what to make of it.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>PHP Task 10</title>
</head>
<body>
<?php 
$conn = mysql_connect("xxxxxx", xxxxxx", "xxxxxxxx");
mysql_select_db("xxxxxxxx", $conn)
or die ('Database not found ' . mysql_error() );
$sql = "SELECT staffName, staffID 
FROM staff";
$rs = mysql_query($sql, $conn)
or die ('Problem with query' . mysql_error());
?>

<form id="staff" action="task7.php" method="get">
<?php 
while($row = mysql_fetch_array($rs)){
echo "<input type="radio" name="staffID" value=<?php echo '".$row["staffID"]."'?>><?php echo ".$row["staffName"]."?>";
};
?>
<p><input type="submit"  value="Submit">
  <input type="reset" value="Reset"></p>
</form>
</body>
</html>
  • 写回答

2条回答 默认 最新

  • duandunzhuo3234 2014-05-16 05:21
    关注

    You have some mistakes in your code. While you are echoing a string with PHP, you don't need to add <?php ?> tags and echo each time like,

    value=<?php echo '".$row["staffID"]."'?>
    

    Change

       while($row = mysql_fetch_array($rs)){
        echo "<input type="radio" name="staffID" value=<?php echo '".$row["staffID"]."'?>><?php echo ".$row["staffName"]."?>";
        };
    

    to

    while($row = mysql_fetch_array($rs)){
        echo "<input type='radio' name='staffID' value='".$row["staffID"]."'>".$row["staffName"];
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c