Page 1 of 1

Hi, im new here need some help with a VERY simple code

Posted: Sun Nov 16, 2003 8:03 am
by InfestedOnes
Hey can someone help me fix this up?

Code: Select all

<?php
 mysql_connect("localhost"," db", "pass"); 
 mysql_select_db("db");
session_start();
session_register("$id");
$id=username;  $sql="select * from bb1_user_table where userid='$id'"; 
$res=mysql_query($sql) or die(mysql_error());$row=mysql_fetch_object($res);
echo "$row->username ";
?>
Since my var id is empty if i did $id=1 it would display user one, i want it to dsiplay whatever username your logged in as, i think it has to do with $id=1 only change it to $id=row username? please help[/quote]

Posted: Sun Nov 16, 2003 8:42 am
by d3ad1ysp0rk

Code: Select all

$sql="SELECT `username` FROM `bb1_user_table` WHERE `userid` = '$id'";
mysql_result(mysql_query($sql), 0,0);
I believe that's what you're looking for.

Posted: Sun Nov 16, 2003 9:02 am
by Cruzado_Mainfrm
note this line:

Code: Select all

<?php
mysql_connect("localhost"," db", "pass"); 
?>
it has an space before 'db', see?

Posted: Sun Nov 16, 2003 9:44 am
by Nay
Guys, it'll also throw up an error, not a valid link resource at line bla bla this way, you need two arguments for mysql_query(). And InfestedOnes, please post here, do not ask for help via a PM. It's under the rules. I'm not trying to be mean or anything, being a newbie is not an excuse either.

Anyhow, corrections:

Code: Select all

<?php
session_start(); // put session start on top

$connection = mysql_connect("localhost","user", "pass"); // store it under a variable so you can use it later on
$database = mysql_select_db("db"); // same thing here

$id = $_GET['username']; // im just guessing it came form a $_GET, $id=username wasn't correct either, you'll need quotes

$_SESSION['id'] = $id; // use $_SESSION and register it AFTER you declare $id

$sql = "SELECT * FROM 'bb1_user_table' WHERE userid='$id'";

$res = mysql_query($sql, $connection) or die(mysql_error()); // you need two arguements for the mysql_query()

$row = mysql_fetch_array($res); // what was it doing in or die()? you want it only to fetch if it died? O_O

echo $row['user']; // what's echo "$row->username ";??? it's not a object, believe me, don't get into OOP so fast
?>
-Nay

Posted: Sun Nov 16, 2003 10:12 am
by InfestedOnes
thanks im gonna try it

Posted: Sun Nov 16, 2003 10:19 am
by InfestedOnes
well if i enter from username this happens:
You have an error in your SQL syntax near 'from bb1_user_table where userid=''' at line 1
EDIT: What im trying to do is display the username of who your logged in as , my var id is empty so i needed id = 1 or whatever number for that username but that only displays the username for that row, how could I display whatever username your logged in as using sessions and select?

Posted: Sun Nov 16, 2003 3:21 pm
by Paddy
Concatenate it like this and see if it works.

Code: Select all

<?php
$sql = "SELECT * FROM 'bb1_user_table' WHERE userid='".$id."'"; 
?>
If that doesn't work replace $id with 1 and see if that even works. If that doesn't or does at least you know where the problem is.

Posted: Sun Nov 16, 2003 3:44 pm
by infolock
also, a few things : are you using mysql or SQL? Also, open up your HTML document file where you type in the USERNAME/PASSWORD, and edit the source. What you are looking for is if you are passing a POST statement in the form itself. If you are, instead of using $_GET, try using $_POST.