Page 1 of 2
Reading from $Profileid
Posted: Wed Aug 08, 2007 10:32 pm
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>
Posted: Wed Aug 08, 2007 11:00 pm
by feyd
Magic?
You're going to need to explain what everything is.
Posted: Wed Aug 08, 2007 11:22 pm
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
Posted: Wed Aug 08, 2007 11:27 pm
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";
Posted: Sun Aug 19, 2007 10:43 pm
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) ?>
Posted: Mon Aug 20, 2007 8:18 am
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....
Posted: Mon Aug 20, 2007 11:12 am
by 4Boredom
mysql
Posted: Mon Aug 20, 2007 10:08 pm
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); ?>
Posted: Mon Aug 20, 2007 10:30 pm
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.
Posted: Mon Aug 20, 2007 10:34 pm
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
Posted: Mon Aug 20, 2007 10:45 pm
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.
Posted: Mon Aug 20, 2007 10:58 pm
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?
Posted: Mon Aug 20, 2007 11:21 pm
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>");
?>
Posted: Mon Aug 20, 2007 11:34 pm
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.
Posted: Mon Aug 20, 2007 11:34 pm
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