duanlei8119 2013-12-01 18:59
浏览 48
已采纳

我有一个带有“postId”的sql表作为字段,我试图在用户点击链接时将其“获取”到一个URL中

My problem is: I have an sql table with "postId" as a field, I'm trying to "get" that into a url when the user clicks a link

$con = mysqli_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);

$result = mysqli_query($con,"SELECT * FROM posts"); //You don't need a ; like you do in SQL

echo "<table border='1'>"; // start a table tag in the HTML

while($row = mysqli_fetch_array($result)){   //Creates a loop to loop through results
echo "<tr><td>" . $row['user'] . "</td><td>" . $row['text'] . "</td><td> <form action="comment.php?=    <?=$row['postId'];?>" method="post">
<input type="button" name="submit" value="Comment">
</form> </td></tr>";  //$row['index'] the index here is a field name//$row['index'] the index here is a field name
}

echo "</table>"; //Close the table in HTML
?>

This is my code, my error states:

Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in /home/content/79/10635579/html/ask/views/logged_in.php on line 24

Although I get that error, I'm probably formatting it wrong or not doing it right overall. Thanks!

EDIT - FULL CODE:

<div>
<!-- if you need user information, just put them into the $_SESSION variable and output them here -->
Hey, <?php echo $_SESSION['user_name']; ?>.
You are logged in.
Try to close this browser tab and open it again. Still logged in! ;)
</div>

<form name="input" action="views/makePost.php" method="get">
Post: <input type="text" name="text">
<input type="submit" value="Submit">
</form>

<?php 

require_once("./config/db.php");

$con = mysqli_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);

$result = mysqli_query($con,"SELECT * FROM posts"); //You don't need a ; like you do in SQL

echo "<table border='1'>"; // start a table tag in the HTML

while($row = mysqli_fetch_array($result)){   //Creates a loop to loop through results
echo "<tr><td>" . $row['user'] . "</td><td>" . $row['text'] ."</td><td> 
<form action='comment.php?postid=".$row['postId']."' method='post'>
<input type='button' name='submit' value='Comment'>
</form> </td></tr>";
}

echo "</table>"; //Close the table in HTML
?>

<div>
<!-- because people were asking: "index.php?logout" is just my simplified form of "index.php logout=true" -->
<a href="index.php?logout">Logout</a>
</div>
  • 写回答

1条回答 默认 最新

  • dongmeiwei0226 2013-12-01 19:08
    关注
     echo "<tr><td>" . $row['user'] . "</td><td>" . $row['text'] ."</td><td> 
    <form action='comment.php?postid=".$row['postId']."' method='post'>
    <input type='submit' name='submit' value='Comment'>
    </form> </td></tr>";
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 ogg dd trandata 报错
  • ¥15 高缺失率数据如何选择填充方式
  • ¥50 potsgresql15备份问题
  • ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
  • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
  • ¥60 pb数据库修改与连接
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错