Jump to content

user id


Html

Recommended Posts

Notice: Undefined variable: q on line 22

mysqli_query() expects parameter 1 to be mysqli, string given on line 22

Undefined variable: row on line 29

Undefined variable: dbc on line 36

Undefined variable: q on line 36

mysqli_query() expects parameter 1 to be mysqli, null give on line 36

<?php
ini_set('display_errors', 1); 
error_reporting(E_ALL);
# Access session.
session_start() ; 
 
# Redirect if not logged in.
if ( !isset( $_SESSION[ 'user_id' ] ) ) { require ( 'login_tools.php' ) ; load() ; }

$user_id = $_SESSION['user_id'];

if (isset( $user_id )) {
    echo '<div>We have a green light that $user_id is set and has a value <div style="width:1em; height: 1em; display: inline-block; background: lime;"></div> and equals: ' . $user_id . '</div>';
} else {
    echo 'We have a red light that $user_id is set, but has NO VALUE <div style="width:1em; height: 1em; display: inline-block; background: red;"> and equals: ' . $user_id . ' </div>';
}
 
# On success retrieve user_id, first_name, and last name from 'users' database.
  if ( empty( $errors ) ) 
  {
    $user_id = "SELECT user_id, first_name, last_name FROM users WHERE user_id='$user_id'" ;  
    $r = mysqli_query ( $user_id, $q ) ;
    if ( @mysqli_num_rows( $r ) == 1 ) 
    
      $row = mysqli_fetch_array ( $r, MYSQLI_ASSOC ) ;
     
 
        echo '<tr><td>' . 
        $row['first_name'] .' '. 
        $row['last_name'] . '<br>'. 
        '</td> </tr>';
  
 
  echo '</table>' ;
 }
$r = mysqli_query($dbc, $q);    
?>

profile.jpg.76277f266272dd1ae2bb3e54971c5906.jpg

Link to comment
Share on other sites

Well it wouldn't as you have not followed my instructions, some of them but! not all of them, and I'm not helping you figure it out! AsI spelled out what you need to do and colour coded it for you. This is what happens when you chop and change code, without understanding what those specific parts of code do.

Link to comment
Share on other sites

Web connection is back, it was down for the weekend.

Right okay, I read what you stated in the post,

<?php
ini_set('display_errors', 1);
error_reporting(E_ALL);
# Access session.
session_start() ;

$user_id = $_SESSION['user_id'];

if (isset( $user_id )) {
    echo '<div>We have a green light that $user_id is set and has a value <div style="width:1em; height: 1em; display: inline-block; background: lime;"></div> and equals: ' . $user_id . '</div>';
} else {
    echo 'We have a red light that $user_id is set, but has NO VALUE <div style="width:1em; height: 1em; display: inline-block; background: red;"> and equals: ' . $user_id . ' </div>';
}
 
# Redirect if not logged in.
if ( !isset( $_SESSION[ 'user_id' ] ) ) { require ( 'login_tools.php' ) ; load() ; }

# On success retrieve user_id, first_name, and last name from 'users' database.
  if ( empty( $errors ) )
  {
    $user_id = "SELECT user_id, first_name, last_name FROM users WHERE user_id='$user_id'" ;  
    $r = mysqli_query ( $user_id, $q ) ;
    if ( @mysqli_num_rows( $r ) == 1 )
    
      $row = mysqli_fetch_array ( $r, MYSQLI_ASSOC ) ;
     
 
        echo '<tr><td>' .
        $row['first_name'] .' '.
        $row['last_name'] . '<br>'.
        '</td> </tr>';
 
 
  echo '</table>' ;
 }

$r = mysqli_query ($dbc, $q);
?>

Why does 29 display, something wrong with row?

Link to comment
Share on other sites

<?php
ini_set('display_errors', 1);
error_reporting(E_ALL);
# Access session.
session_start() ;

$user_id = $_SESSION['user_id'];

# Redirect if not logged in.
if ( !isset( $_SESSION[ 'user_id' ] ) ) { require ( 'login_tools.php' ) ; load() ; }

if (isset( $user_id )) {
    echo '<div>We have a green light that $user_id is set and has a value <div style="width:1em; height: 1em; display: inline-block; background: lime;"></div> and equals: ' . $user_id . '</div>';
} else {
    echo 'We have a red light that $user_id is set, but has NO VALUE <div style="width:1em; height: 1em; display: inline-block; background: red;"> and equals: ' . $user_id . ' </div>';
}

# On success retrieve user_id, first_name, and last name from 'users' database.
  if ( empty( $errors ) )
  {
    $user_id = "SELECT user_id, first_name, last_name FROM users WHERE user_id='$user_id'" ;  
    $r = mysqli_query ( $user_id, $q ) ;
    if ( @mysqli_num_rows( $r ) == 1 )
    
      $row = mysqli_fetch_array ( $r, MYSQLI_ASSOC ) ;
     
 
        echo '<tr><td>' .
        $row['first_name'] .' '.
        $row['last_name'] . '<br>'.
        '</td> </tr>';
 
 
  echo '</table>' ;
 }

$r = mysqli_query ( $user_id );
?>

Link to comment
Share on other sites

When you run that you're getting a notice about an undefined variable called $q, right?  Well, look at the line number it's referring you to.  Why are you using an undefined variable there, and what should the variable be?

http://php.net/manual/en/mysqli.query.php

You really need to pay attention to the error messages and figure out what they mean and why.  PHP is trying to tell you what the problem is.  Listen to it.

Link to comment
Share on other sites

I guess this will be a similar process for a comment posting to the db, which I have from the example file of the book I have on creating a forum.

Similar process to display a comment on a session user id page

Link to comment
Share on other sites

Well I actually took a look at the comment files, and I can post to the table without having needed to be logged in, so like the profile name, it would need to have some kind of code that identifies a user with a control panel page, so when posting a comment it works for that index page of the registered user. Having thought about it what with little I know and have, I can't see how it could be done, other than having numerous tables for a new user's name.

Obviously I'm getting ahead of what I have been trying to do, but I just thought I'd think into it a little to see how it could be done.

Link to comment
Share on other sites

Once a user is authorized his user_id is the key on saving comments by that user in a separate table. The user_id will not be unique within this table like it would be in users table, as comments will be multiple. You will be using one user_id from users table to many user_is in comments table to retrieve comments from that specific user. IF THAT IS WHAT you are referring to?

Link to comment
Share on other sites

Yes a user will post a comment to forum table, and the session id will retrieve that user's comment and display it on the index, so just like the name is stored in the users table.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...