Re: Select record by ID

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sun, January 28, 2007 5:21 pm, nitrox . wrote:
> Im trying to display one record at a time by ID. Well im getting a
> blank
> page. Ive looked over my code and tried 20 different ways to get it to
> work
> to no avail. So any pointers on what Im doing wrong would be great.
> here is
> the code im working with so far.

First, be sure you are using "View Source" in your browser, so that
something like:

<unclosed tag will HIDE ALL this content.... >

> <?php
> include("db.php");

include is not actually a function, and doesn't need parens, so the
()s here are just kinda silly...

>         $result = mysql_query("SELECT * FROM inf_member WHERE
> user_id='$user_id' ");

You need *SOME* kind of check here on whether your query succeeded.

The canonical example is:
$result = mysql_query(...) or die(mysql_error());

It would also be wise to get in the habit now of configuring your
web-server to NOT display_errors but to log_errors in your php.ini (or
in .htaccess with php_value) and then to read your error logs instead
of your web page.

The point being to not expose the internal workings of your
application to the Bad Guys who use such info to make it easier to
break into your machine.

Read this over and over until you understand all of it:
http://phpsec.org

>         while($myrow = mysql_fetch_assoc($result))
>               {
>                      echo "<b>";
>                      echo $myrow['user_name'];
>                      echo "</b>";
>                      echo $myrow['rank'];
> 					 echo "</b>";
>                      echo $myrow['country'];
> 					 echo "</b>";
>                      echo $myrow['email'];
>                      echo "</b>";
>                      echo $myrow['quote'];
>                      echo "</b>";
>                      echo $myrow['config'];
> 					 echo "</b>";
> 					 echo $myrow['map'];
>                      echo "</b>";
>                      echo $myrow['gun'];
>                      echo "</b>";
>                      echo $myrow['brand'];
> 					 echo "</b>";
> 					 echo $myrow['cpu'];
> 					 echo "</b>";
>                      echo $myrow['ram'];
>                      echo "</b>";
>                      echo $myrow['video'];
>                      echo "</b>";
>                      echo $myrow['sound'];
> 					 echo "</b>";
> 					 echo $myrow['monitor'];
>                      echo "</b>";
>                      echo $myrow['mouse'];
>                      echo "</b>";
>                      echo $myrow['brand'];
> 					 echo "</b>";

Instead of a bunch of echo statements like this, you may want to
consider the 'heredoc' syntax, or at least fewer echo statements such
as:
echo "<b>$myrow[brand]</b><br />\n";

Or, you could do like this:
foreach($myrow as $field => value){
  echo "$field: <b>$value</b><br />\n";
}
instead of all those echo statements.

>              }
> ?>


-- 
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some starving artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux