duankanyi6539 2013-12-18 07:12
浏览 65

MySQL数据库PHP特定行

My current code is this:

   <?php
$con=mysqli_connect("stevie.heliohost.org","rbxdataa_Art","mydata123art");
if (mysqli_connect_errno()) {
    printf("Connect failed: %s
", mysqli_connect_error());
    exit();
}


mysqli_select_db($con, "rbxdataa_Data");
$Amount=$_GET["Amount"];
$GetType=$_GET["Type"];
$sql = "SELECT * FROM EventRecord WHERE EventType='$GetType' ORDER BY EventId DESC";
$sql_run = mysqli_query($con, $sql);
while($sql_row = mysqli_fetch_assoc($sql_run)){
   echo $sql_row['EventId'].'<br>';
}
mysqli_close($con);
?>

As I am currently very new to PHP and MySQL, I have no idea why this code will not work. I am also confused as to how I would make it echo only the top ($Amount) as determined by how large the "EventId" value is. My intent is to gather the [$Amount] highest rows in the table with the EventType $GetType. I am aware of SQL Injection vulnerability, however for my purposes this does not affect me. Error: "Parse error: syntax error, unexpected T_STRING on line 4"

  • 写回答

4条回答 默认 最新

  • dstjh46606 2013-12-18 07:16
    关注

    As I see, you have a normal code, may be you have no any rows in DataBase with requested EventType ?

    At second: you have SQL Injection vulnerability. Use PDO and Prepared Statements instead your mysqli_query code.

    评论

报告相同问题?

悬赏问题

  • ¥15 2024-五一综合模拟赛
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭