dongliufa6380 2016-03-31 10:28
浏览 26

在php中打印mysql数据库[重复]

This question already has an answer here:

i have a mysql database name cstudents with table students and sid,sname,sdiv and passyr as the table columns. i intend to print this entire table. here is the code i tried:

$con3=mysql_connect(DB_HOST1,DB_USER1,DB_PASSWORD1) or die ("failed to connect to mysql".mysql_error());
$db=mysql_select_db(DB_NAME1,$con3) or die ("failed to connect to mysql".mysql_error());
$query = "SELECT sid, sname, rollno, passyr FROM cstudents.student;
$result = mysql_query($query) or die ('Error:'.mysql_error($query));
while ($row = mysql_fetch_assoc($result,mysql_both)) {
    echo $row['sid'];
    echo $row['sname'];
    echo $row['sdiv'];
    echo $row['passyr'];
}

executing this gives: Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING)

please help!

</div>
  • 写回答

1条回答 默认 最新

  • dsfew215211 2016-03-31 10:30
    关注

    You have missed closing double quotes in your query, instead of:

    $query = "SELECT sid, sname, rollno, passyr FROM cstudents.student;
    

    must be:

    $query = "SELECT sid, sname, rollno, passyr FROM cstudents.student";
    

    And one suggestion: start using mysqli_* functions instead of already depreciated mysql_*.

    评论

报告相同问题?

悬赏问题

  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?