Reading from $Profileid

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!

Moderator: General Moderators

4Boredom
Forum Contributor
Posts: 176
Joined: Tue Nov 08, 2005 4:29 pm

Reading from $Profileid

Post by 4Boredom »

How do I get this to read these details based off of $profileid

I dont want it to read the name of the logged on user

Code: Select all

<b>User Details:</b><br>
  <b>Name:</b> 
  <?php if(isset($user_first_name)){print( ucfirst(strtolower($user_first_name)));} ?>
  <br>
  <b>Gender:</b> 
  <?php if(isset($user_gender)){print(ucfirst(strtolower($user_gender)));} ?>
  <br>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Magic?

You're going to need to explain what everything is.
4Boredom
Forum Contributor
Posts: 176
Joined: Tue Nov 08, 2005 4:29 pm

Post by 4Boredom »

their first name and their gender (typed out)...

i want something like

print user_first_name
where $userid = $profileid

not sure how to dio it tho
User avatar
iknownothing
Forum Contributor
Posts: 337
Joined: Sun Dec 17, 2006 11:53 pm
Location: Sunshine Coast, Australia

Post by iknownothing »

is it in a database, a file or what?

if its a database you can use the WHERE clause in sql.

eg.

Code: Select all

$sql = "SELECT * FROM user WHERE profileid = $profileid";
4Boredom
Forum Contributor
Posts: 176
Joined: Tue Nov 08, 2005 4:29 pm

Post by 4Boredom »

ok so this obviously doesnt work but is what i need to get touched up

Code: Select all

<?$sql = "SELECT * FROM user WHERE $userid= $profileid"; ?>
        
  <b>User Details:</b><br>
  <b>Name:</b>  <?php (print($user_first_name) WHERE $userid = $profileid)  ?>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

You will need to add calls to request that your database perform the query and to retrieve the data, if found.

Maybe mysql_query(), mysql_num_rows() and mysql_fetch_assoc() could be of use, but I don't know what database you're using....
4Boredom
Forum Contributor
Posts: 176
Joined: Tue Nov 08, 2005 4:29 pm

Post by 4Boredom »

mysql
4Boredom
Forum Contributor
Posts: 176
Joined: Tue Nov 08, 2005 4:29 pm

Post by 4Boredom »

IM trying.. I tried looking up what you said and this is the best I can come up with and still get this error

Fatal error: Call to undefined function: () in profiletemplate.php on line 51

Code: Select all

<? $query = $sprint("SELECT user_first_name, gender FROM users WHERE userid = 'profileid'"); 
  
  // Perform Query
$result = mysql_query($query);

?>
        
  <b>User Details:</b><br>
  <b>Name:</b> 
  <?php print($user_first_name);  ?>
  <br>
  <b>Gender:</b> 
  <?php print($gender); ?>
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

Fatal error: Call to undefined function: () in profiletemplate.php on line 51
Really, now?

You should look at some tutorials (or code snippets from the PHP manual, itself) on basic database interaction with PHP and MySQL.
4Boredom
Forum Contributor
Posts: 176
Joined: Tue Nov 08, 2005 4:29 pm

Post by 4Boredom »

well i figured its an easy fix for someone who knows what they are doing and i have a lot of pressure on me to get this code done so I was just trying to see if anyone can help..... I help people all the time....

but ill look at the manual.. thanks
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

4Boredom wrote:but ill look at the manual.. thanks
The mysql_fetch_* functions in particular.

mysql_fetch_object()
mysql_fetch_assoc()
mysql_fetch_row()
etc.
User avatar
iknownothing
Forum Contributor
Posts: 337
Joined: Sun Dec 17, 2006 11:53 pm
Location: Sunshine Coast, Australia

Post by iknownothing »

Code: Select all

<? $query = $sprint("SELECT user_first_name, gender FROM users WHERE userid = 'profileid'");
what is $sprint and why is it there?
4Boredom
Forum Contributor
Posts: 176
Joined: Tue Nov 08, 2005 4:29 pm

Post by 4Boredom »

ok i fixed it mostly... database works thanks alll

now I just have to figure out why only gender pastes lmao

heres the solution

Code: Select all

<?
$info = mysql_query("SELECT * FROM `userbase` WHERE userid = '{$profileid}' ");
if(!$info){
	die("Could not get user info.");
}
//$info = mysql_fetch_array($info); 

$info = mysql_query("SELECT first_name, gender, location, age, party FROM userbase");

?>
        
  <b>User Details:</b><br>
  <b>Name:</b> 
 <?php print($user_first_name); ?>
  <br>
  <b>Gender:</b> 
  <?php 

if ($user_gender == "M"){
	echo("Male");} 
if ($user_gender == "F"){
	echo("Female");} 
if ($user_gender == ""){
	echo("?");} 

  ?>
  <br>
  <b>Age:</b> 
  
  <? print($user_age); 
  print($user_gender);?>
 
  <br>
  <b>Location:</b>
  <? print($user_location); ?>
  <br>


  <b>Party:</b> 
  <? if ($user_party == "D"){
echo("Democrat<br>");}
if ($user_party == "R"){
echo("Republican<br>");}
if ($user_party == "I"){
echo("Independent<br>");}
if ($user_party == ""){
echo("Not Specified<br>");}
echo("<br>");

?>
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

You realize your first query does nothing for your script since you override immediately with the result resource from another query? And you should probably be using regular opening php tags instead of short tags.

As for all the $user* variables you are using... where are those given their values from? I can't see them being set anywhere in the script.
4Boredom
Forum Contributor
Posts: 176
Joined: Tue Nov 08, 2005 4:29 pm

Post by 4Boredom »

The database is set up the same.... why isnt the other stuff working

userid first_name last_name party gender age location
1 Derek Testuser D M 22 Franklin, NH


also heres the fetch

Code: Select all

// Get user Information from userbase db

$info2 = mysql_query("SELECT * FROM `userbase` WHERE email_address = '{$email_address}' ");
if(!$info2){
	die("Could not get user info");
}
$info2 = mysql_fetch_array($info2);
$userid = $info2['userid'];

// Get other required user infomation 
$first_name = $info2['first_name']; 
$last_name = $info2['last_name']; 
$email_address = $info2['email_address']; 
$party = $info2['party']; 
$age = $info2['age'];
$location = $info2['location'];
$gender = $info2['gender'];
// Fix for any place you put session instead of just the variable.
$_SESSION['first_name'] = $first_name;
$_SESSION['last_name'] = $last_name;
$_SESSION['email_address'] = $email_address;
$_SESSION['party'] = $party;
$_SESSION['age'] = $age;
$_SESSION['location'] = $location;
$_SESSION['gender'] = $gender;
am i doing anything stupid on any of these codes? The rest should work
Post Reply