php-mysql页面上没有显示任何内容

时间:2013-03-10 14:46:29

标签: php mysql

您好,以下内容未在网页上显示任何内容。哪里出错了?

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 个答案:

答案 0 :(得分:0)

您未在此行中;之后添加$id

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

mysql_query()是一个函数(也不再使用mysql_*函数,它们已被弃用!)因此不应该使用{{1}调用它在前面:

$

答案 1 :(得分: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。

答案 2 :(得分:0)

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

  1. 是否设置了$id?它是否有整数值?

  2. 语法错误:

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

    需要一个分号(;)列39.(在这种情况下,如果需要,则不是100%确定,但总是确定)

  3. 数据库中是否有记录?

  4. 连接顺序在哪里?

  5. 您选择了数据库吗?

  6. 你还在使用mySQL吗?

  7. 现在看来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?';
    

答案 3 :(得分: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>