PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
<?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]
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.
<?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
?>
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?
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.