Sorry
on my userinfo.php page
it currently retrieves and displays the username and email address but now I want to retrieve and display the Full name of the visitor from the visitors table
I know it can be done using JOIN but not 100% sure how to code it in
I did try from another php file that uses JOIN but it only only displays the first letter of the full name
The code I have is below in the userinfo.php file
[code=php]
<?php
ini_set(‘display_startup_errors’,1);
ini_set(‘display_errors’,1);
error_reporting(-1);
?>
<?php
/**
* UserInfo.php
*
* This page is for users to view their account information
* with a link added for them to edit the information.
*
* Updated by: The Angry Frog
* Last Updated: October 26, 2011
*/
include(“include/session.php”);
global $database;
$config = $database->getConfigs();
if (!isset($_GET[‘user’])) {
header(“Location: “.$config[‘WEB_ROOT’].$config[‘home_page’]);
}
?>
<?php
$db = mysqli_connect(“” , “”, “”) or die(“Check connection parameters!”);
// Optionally skip select_db and use: mysqli_connect(host,user,pass,dbname)
mysqli_select_db($db,””) or die(mysqli_error($db));
if (mysqli_connect_error()) {
die (‘Failed to connect to MySQL’);
} else {
/*SUCCESS MSG*/
echo ”;
}
$sqlCommand3 = “SELECT v.visitor_id, visitor_name
FROM visitors v
JOIN users”;
$query = mysqli_query($db, $sqlCommand3) or die (mysqli_error($db));
//fetch the data from the database
while ($row = mysqli_fetch_array($query)) {
$visitor_name = $row[‘visitor_name’];
}
?>
<?php
$title = “My Account – The Tax Elephants”;
$pgDesc=””;
$pgKeywords=””;
include ( ‘includes/header.php’ );
?>
<!–CONTENT–>
<div id=”column-whole”>
<?php
/* Requested Username error checking */
$req_user = trim($_GET[‘user’]);
if(!$req_user || strlen($req_user) == 0 ||
!preg_match(“/^[a-z0-9]([0-9a-z_-s])+$/i”, $req_user) ||
!$database->usernameTaken($req_user)){
die(“Username not registered”);
}
/* Logged in user viewing own account */
if(strcmp($session->username,$req_user) == 0){
echo “<h1>My Account</h1>”;
}
/* Visitor not viewing own account */
else{
echo “<h1>User Info</h1>”;
}
/* Display requested user information – add/delete as applicable */
$req_user_info = $database->getUserInfo($req_user);
/* Username */
echo “<b>Username: “.$req_user_info[‘username’].”</b><br>”;
/* Email */
echo “<b>Email:</b> “.$req_user_info[’email’].”<br>”;
echo “<strong>Name:</strong> “.$visitor_name[‘visitor_name’].”<br>”;
/**
* Note: when you add your own fields to the users table
* to hold more information, like homepage, location, etc.
* they can be easily accessed by the user info array.
*
* $session->user_info[‘location’]; (for logged in users)
*
* $req_user_info[‘location’]; (for any user)
*/
/* If logged in user viewing own account, give link to edit */
if(strcmp($session->username,$req_user) == 0){
echo ‘<br><a href=”useredit.php”>Edit Account Information</a><br>’;
}
/* Link back to main */
echo “<br><a href=’process.php’>Logout</a><br>”;
?>
</div>
<?php
// Free the results
mysqli_free_result($query);
//close the connection
mysqli_close($db);
?>
<!–CONTENT–>
<?php include( ‘includes/footer.php’ ); ?>
I have added visitor_id in the users table and made it INT(11) at the end of the users table and is currently saying 0 but the visitor_id of the user I am trying to match it with is 66
I looked in database.php as going by another php file using JOIN, it has INSERT INTO as well so it looks like it inserts the visitor_id into two two tables so I thought it already adds visitor_id into visitors table and thought it would also add visitir_id into the users table but has not worked that way
the database.php coding I have is below
[code=php]
function addNewUser($username, $password, $email, $token, $usersalt){
$time = time();
$config = $this->getConfigs();
/* If admin sign up, give admin user level */
if(strcasecmp($username, ADMIN_NAME) == 0){
$ulevel = ADMIN_LEVEL;
/* Which validation is on? */
}else if ($config[‘ACCOUNT_ACTIVATION’] == 1) {
$ulevel = REGUSER_LEVEL; /* No activation required */
}else if ($config[‘ACCOUNT_ACTIVATION’] == 2) {
$ulevel = ACT_EMAIL; /* Activation e-mail will be sent */
}else if ($config[‘ACCOUNT_ACTIVATION’] == 3) {
$ulevel = ADMIN_ACT; /* Admin will activate account */
}
$password = sha1($usersalt.$password);
$userip = $_SERVER[‘REMOTE_ADDR’];
$query = “INSERT INTO “.TBL_USERS.” SET username = :username, password = :password, usersalt = :usersalt, userid = 0, userlevel = $ulevel, email = :email, timestamp = $time, actkey = :token, ip = ‘$userip’, regdate = $time, visitor_id = $visitor_id”;
$stmt = $this->connection->prepare($query);
return $stmt->execute(array(‘:username’ => $username, ‘:password’ => $password, ‘:usersalt’ => $usersalt, ‘:email’ => $email, ‘:token’ => $token));
}