-3

您好以下不是在网页上播种任何东西。我哪里出错了?

The following is a link to profile.php
?>
<a href="profile.php?id=<?php echo $id ?>"><?php echo $id;?></a>
<?PHP

========================================= 这是链接的php文件profile.php

<html>

<body bgcolor='#4c5865'>

<p style="position: absolute ; top: 0; text-align: left><font face="geneva" size='1' color="#ccc"><a href="cbs.php" ><b><font color="white">Home</font></p></a>
<?php

include("db1.php");
$id=$_GET['id'];

$result = $mysql_query ("select agt,dvd FROM agttot where agt='$id'");

// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array( $result )) {
$ac =$row[0];
$dc =$row[1];
$bc =$row[2];

 //   echo "<tr bgcolor='#a9a9a9'><td align='right'>";
    print $ac;
 //   echo "</td><td align='right'><b>"; 
    print $dc;
}
?>
</body>
</html>
4

4 回答 4

0

尝试这个

   <html>

  <body bgcolor='#4c5865'>

  <p style="position: absolute ; top: 0; text-align: left><font face="geneva" size='1' color="#ccc"><a href="cbs.php" ><b><font color="white">Home</font></p></a>
 <?php

 include("db1.php");
 $id=$_GET['id'];

$result = $mysql_query ("select agt,dvd FROM agttot where agt='$id'");

// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array( $result )) {
$ac =$row['agt'];
$dc =$row['dvd'];  // you dont have to make numbers here but the column names as it saids in your query
$bc =$row[2];    // you dont have to make numbers here but the column names as it saids in your query

//   echo "<tr bgcolor='#a9a9a9'><td align='right'>";
echo $ac.'<br />';
//   echo "</td><td align='right'><b>"; 
echo  $dc.'<br />';
}
?>
</body>
</html>
于 2013-03-10T15:07:06.687 回答
0

我不是 100% 确定你的问题是什么。我会检查一些有问题的区域:

  1. 定了吗$id?它有一个整数值吗?

  2. 这里的语法错误:

    <a href="profile.php?id=<?php echo $id ?>"><?php echo $id;?></a>
    

    需要分号 (;) 第 39 列。(不是 100% 确定在这种情况下是否需要,但始终确定)

  3. 数据库中有记录吗?

  4. 连接顺序在哪里?

  5. 你选择了数据库吗?

  6. 你还应该使用 mySQL 吗?

看到 mySQL 现在已贬值,这里有一个 mySQLi 示例(程序):

$con=new mysqli_connect('location','user','password','database');
$query=mysqli_prepare('SELECT agt,dvd FROM agttot WHERE agt=?',$con);
mysqli_stmt_bind_param(, $query, 'i', intval($_GET['id']));
mysqli_stmt_execute($query);
mysqli_stmt_bind_result($query,$agt,$dvd);

while(mysqli_stmt_fetch($query)){
    $result[]='<tr><td>'.$agt.'</td><td>'.$dvd.'</td></tr>';
}

mysqli_stmt_close($query);
mysqli_close($con);

echo(isset($result))?$result:$_GET['id'].' < is this a valid record?';
于 2013-03-10T15:06:55.190 回答
0

您应该在将“$id”放入您的 SQL 之前对其进行转义。

您的 mysql_query 在函数名之前包含一个额外的 $:

$result = **$**mysql_query ("select agt,dvd FROM agttot where agt='$id'"); 

应该

$result = mysql_query ("select agt,dvd FROM agttot where agt='$id'"); 

PS,避免使用 mysql_ 函数集,它们很快就会被弃用。使用 mysqli_ 或 PDO。

于 2013-03-10T15:03:04.923 回答
0

您没有在此行中 添加;after :$id

<a href="profile.php?id=<?php echo $id ?>"><?php echo $id;?></a>

mysql_query()是一个函数(也不再使用mysql_*函数,它们已被弃用!)所以它不应该$在前面用 a 调用:

$result = $mysql_query ("select agt,dvd FROM agttot where agt='$id'");

于 2013-03-10T14:59:01.593 回答