Html Posted October 25, 2018 Author Share Posted October 25, 2018 I was trying to edit the file on the free host, but got logged out, couldn't connect to line on socket. Link to comment Share on other sites More sharing options...
Html Posted October 27, 2018 Author Share Posted October 27, 2018 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); ?> Link to comment Share on other sites More sharing options...
dsonesuk Posted October 27, 2018 Share Posted October 27, 2018 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 More sharing options...
Html Posted October 29, 2018 Author Share Posted October 29, 2018 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 More sharing options...
dsonesuk Posted October 29, 2018 Share Posted October 29, 2018 Every time you do an alteration it gets worse and worse! Go back to previous posted code where $dbc, $q, $r were correctly used, and return it to that state. Link to comment Share on other sites More sharing options...
Html Posted October 29, 2018 Author Share Posted October 29, 2018 <?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 More sharing options...
justsomeguy Posted October 29, 2018 Share Posted October 29, 2018 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 More sharing options...
dsonesuk Posted October 30, 2018 Share Posted October 30, 2018 This code was more correct than the mutilated code you have now! http://w3schools.invisionzone.com/topic/58287-user-id/?page=2&tab=comments#comment-320144 Link to comment Share on other sites More sharing options...
Html Posted November 2, 2018 Author Share Posted November 2, 2018 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 More sharing options...
justsomeguy Posted November 2, 2018 Share Posted November 2, 2018 The vast majority of PHP scripts involve getting submitted data, interacting with a database, etc. That's why you need to learn those basics. Link to comment Share on other sites More sharing options...
Html Posted November 5, 2018 Author Share Posted November 5, 2018 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 More sharing options...
dsonesuk Posted November 5, 2018 Share Posted November 5, 2018 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 More sharing options...
Html Posted November 6, 2018 Author Share Posted November 6, 2018 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now