开发者

Retrieve 1 value that links to all values from database

So I'm trying to display a list of all users in my database... each one with a link that will display their own information (in this case only displays user again and password), heres my code...

<?php
  mysql_connect('localhost','user','password')or die ('Connection Failed: '.mysql_error());
  mysql_select_db('name')or die ('Error to select database '.mysql_error());
$result = mysql_query("SELECT * FROM usuarios ORDER BY ID");



echo "<table border='0'>
<tr>
<th>UserName</th>
</tr>";

   while ($row = mysql_fetch_array($result))
   {
    ec开发者_如何学运维ho "<tr>";
    echo '<td><a href="user.php?id='.$row['id'].'">' . $row['usuario'] . '</a></td>';
    echo "</tr>";
   }
echo "</table>";

?>

I get the ID of each user through the URL to be a new variable in my user.php page to recognize each one...

    <?php 
      $numusu = $_GET['id']; 
      $result = mysql_query("SELECT * FROM usuarios WHERE id=`$numusu`");
      while ($row = mysql_fetch_array($result))
   {
      echo "<table><tr>";
      echo "<td>User:" . $row['usuario'] . "</td>";
      echo "<td>Password:" . $row['password'] . "</td>";
      echo "</tr></table>";
    }
     ?>

But for some reason I'm not able to display anything in user.php, I get the ID value and all just missing the information I just get an error

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /site/test/test/test/login_php/user.php on line 15

What am I doing wrong? Please help me!


The query should be SELECT * FROM usuarios WHERE id='$numusu'. Backticks only work for table and database names.


When you get Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource, it usually means $result is null and/or mysql_query failed. If you change the query to

$result = mysql_query("...") or die(mysql_error());

It should tell you that something like Unknown column '1' in 'where clause'.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜