Jump to content

Archived

This topic is now archived and is closed to further replies.

master82

Blank output problem

Recommended Posts

What is wrong with this code?

[code]<?php
include("database.php");
$userstable = mysql_query("SELECT * FROM users WHERE userid = '1'");
if (!$userstable) {
  echo 'Could not run users query: ' . mysql_error();
  exit;
}
$user = mysql_fetch_row($userstable);

//testing
echo $user[userid];
echo $user[username];
?> [/code]

When I run it I donr get any errors, just a blank page ???

Share this post


Link to post
Share on other sites
try this:

[quote]<?php
include("database.php");
$userstable = mysql_query("SELECT * FROM users WHERE userid = '1'");
if (!$userstable) {
  echo 'Could not run users query: ' . mysql_error();
  exit;
}
$user = mysql_fetch_row($userstable);

//testing
echo $user[0];
echo $user[1];
?> [/quote]

you may need to edit the numbers to match the colum number.
Also RTFM [url=http://uk.php.net/manual/en/function.mysql-fetch-row.php]http://uk.php.net/manual/en/function.mysql-fetch-row.php[/url]

Share this post


Link to post
Share on other sites
That works great!

But is there a way I can assign the values using their fieldnames rather than a number?

eg

$user[username] (would show the username)

rather than

$user[1]

is it possible?

Share this post


Link to post
Share on other sites
Err, i'm sure i do that.

Add [quote]seesion_start();[/quote] at the top.

Then, if you want their username for example.

[quote]$_SESSION['username'][/quote]

Share this post


Link to post
Share on other sites
[quote]Description
array mysql_fetch_row ( resource result )

Returns a numerical array that corresponds to the fetched row and moves the internal data pointer ahead.
[/quote]

to use mysql_fetch_object

then use $user->username;

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.