Jump to content

Html

Members
  • Content Count

    458
  • Joined

  • Last visited

Everything posted by Html

  1. Html

    user id

    Hi, Okay, I'm going to need some pointers, can I setup a profile.php with the code that will use a session to grab the id from a user? For a change I thought why not view the sessions here on this site php 5 sessions I guess they are good to use, https://www.w3schools.com/php/php_sessions.asp <?php // Start the session session_start(); ?> <!DOCTYPE html> <html> <body> <?php // Set session variables $_SESSION["favcolor"] = "green"; $_SESSION["favanimal"] = "cat"; echo "Session variables are set."; ?> So "1" needs an index page, So home.php <html> <body> <center> <img src="header2018may15.jpg"> </center> <?php # DISPLAY COMPLETE LOGGED IN PAGE. # Access session. session_start() ; # Redirect if not logged in. if ( !isset( $_SESSION[ 'user_id' ] ) ) { require ( 'login_tools.php' ) ; load() ; } # Set page title and display header section. $page_title = 'Home' ; include ( 'includes/header.html' ) ; # Display body section. echo "<h1>HOME</h1><p>You are now logged in, {$_SESSION['first_name']} {$_SESSION['last_name']} </p>"; # Create navigation links. echo '<p><a href="forum.php">Forum</a> | <a href="shop.php">Shop</a> | <a href="goodbye.php">Logout</a></p>'; # Display footer section. include ( 'includes/footer.html' ) ; ?> <br /> <br /> <br /> <img src="bottomheader.jpg"> </body> </html> As seen there is a session identifier there with name and last name, so this page knows to use what is from the db I would think, # Redirect if not logged in. if ( !isset( $_SESSION[ 'user_id' ] ) ) { require ( 'login_tools.php' ) ; load() ; } This part here is looking to login_tools, so that is where the the logic is, # On success retrieve user_id, first_name, and last name from 'users' database. if ( empty( $errors ) ) { $q = "SELECT user_id, first_name, last_name FROM users WHERE email='$e' AND pass=SHA2('$p',256)" ; $r = mysqli_query ( $dbc, $q ) ; if ( @mysqli_num_rows( $r ) == 1 ) { $row = mysqli_fetch_array ( $r, MYSQLI_ASSOC ) ; return array( true, $row ) ; } This above is from login tools, so I could use that above, <?php ?> I did read through the sessions in the Learning Php book, and looked at some of the code examples, just no good for me.
  2. Html

    user id

    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.
  3. Html

    user id

    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.
  4. Html

    Finding Forums

    Definitely needs changing.
  5. Html

    user id

    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
  6. Html

    user id

    <?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 ); ?>
  7. Html

    user id

    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?
  8. Html

    user id

    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); ?>
  9. Html

    user id

    I was trying to edit the file on the free host, but got logged out, couldn't connect to line on socket.
  10. Html

    user id

    Notice: Undefined variable: user_id on line 13 Warning: mysqli_query() expects at least 2 parameters, 1 given on 14 Notice: Undefined variable: row on line 21 If I remove the comma, the error messages appear ( $user_id, ) And whether user_id or first name doesn't make any difference. I changed it back to first name.
  11. Html

    user id

    $row['user_id'] .' '. The errors before tinkering with it were, lines 21, and 13, and 14. $r = mysqli_query ( $user_id, ) ; Once I changed them, the blank page was displayed. From the column in the db? email is just that email, user_id is exactly that as the image in the top post displays. Unless you are getting at the fact that there is no underscore in the actual column name?
  12. Html

    user id

    I managed to try out the file, web host is back up since last week, so yes, I tried out, and a bunch of errors, I tried tickering with it, and got this result, but yes it doesn't do what it should. <?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() ; } # 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 email='$user_id'" ; $r = mysqli_query ( $user_id, ) ; if ( @mysqli_num_rows( $r ) == 1 ) $row = mysqli_fetch_array ( $r, MYSQLI_ASSOC ) ; echo '<tr><td>' . $row['user_id'] .' '. $row['last_name'] . '<br>'. '</td> </tr>'; echo '</table>' ; } ?>
  13. Html

    user id

    Okay, I will respond as soon as the free host is up again, there appears to be downtime. At least I have got this corrected, partially. Thanks
  14. Html

    user id

    <?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() ; } # On success retrieve user_id, first_name, and last name from 'users' database. if ( empty( $errors ) ) { $q = "SELECT user_id, first_name, last_name FROM users WHERE email='$user_id'" ; $r = mysqli_query ( $dbc, $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>' ; } mysqli_close($dbc); ?> Okay the official php checker has given an okay with this.
  15. Html

    user id

    Sure, I don't know the syntax and spacing of the code, as I found out when I typed out the forum tutorial page for page, and then you got me the files. So I got somewhere with that. Okay, the code to get this to work is missing, and incorrect. Then this isn't quite as simple as I thought, you stated you left certain clues about the select query part. <?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() ; } # On success retrieve user_id, first_name, and last name from 'users' database. if ( empty( $errors ) ) { $q = "SELECT user_id, first_name, last_name FROM users WHERE email='$user_id'" ; $r = mysqli_query ( $dbc, $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>' ; } mysqli_close($dbc); ?> Not sure if that edit works.
  16. Html

    user id

    <?php $page_title = 'forum' include('includes/header.html'); require ('\connect_db.php'); $sql = 'SELECT * FROM forum'; $result = mysql_query($dbc, $sql); if ( mysqli_num_rows($result)>0) { echo '<table><tr><th>Posted By</th> <th>Subject</th><th id="msg">Message</th></tr>'; while ($rows=mysqli_fetch_array($result, MYSQLI_ASSOC)) { echo '<tr><td>'. $row['first_name'].''. $row['last_name'].'<br>'. $row['post_date'].'</td><td>'. $row['subject'].''. $row['message'].''. } echo'</table>'; else { echo '<p>There are currently no messages.</p>'; } echo'<p><a href="post.php">Post Message</a></p>'; mysqli_close($dbc); incluide('includes/footer.html'); ?> According to the forum code, there is one of those curly braces just under echo. if ( empty( $errors ) ) { $q = "SELECT user_id, first_name, last_name FROM users WHERE email='$user_id'" ; $r = mysqli_query ( $dbc, $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>' ; } ?> So this bottom part of profile was missing one of those, from your hint.
  17. Html

    user id

    The only part I focused on was the comment box, or forum, which I simply just downloaded the files from the site, since I tried typing it all out, and it was a waste of time since it didn't work. So I took that short cut. I then viewed the other files, and noticed I could use that login system as they were from a book called Php and mysql. So yes, looked at the code, and took the forum part about inserting data, and used the user id part from the login and put them together, as displayed. And you've given me some pointers, which I'm struggling with. The php 7 basic book is just that, it doesn't really go into explanations word for word. As for the Learning php book, no good really for me. That was why I preferred a video. Forget about that. line 23 is an error according to that check system. I tried this, and now 30 is the problem. <?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() ; } # On success retrieve user_id, first_name, and last name from 'users' database. if ( empty( $errors ) ) { $q = "SELECT user_id, first_name, last_name FROM users WHERE email='$user_id'" ; $r = mysqli_query ( $dbc, $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>' ; } ?>
  18. Html

    user id

    <?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() ; } # On success retrieve user_id, first_name, and last name from 'users' database. if ( empty( $errors ) ) { $q = "SELECT user_id, first_name, last_name FROM users WHERE email='$user_id'" ; $r = mysqli_query ( $dbc, $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><td>' . </td> </tr>'; } echo '</table>' ; } ?> I'm not sure about that, bare in mind I only have the php 7 book which has a chapter on variables, never read that part, from what I can gather it mentions user, but nothing about a $user, you state it doesn't matter that much. In the defining constants page, 'USER', 'Mike'); echo 'Hello' . USER ; Hello how is your puppy is the statement example. You hare using php 7.0.4
  19. Html

    user id

    I don't quite know what to state to where does the $user_id originates from, in the db it is simply user_id, so neither that or $id work in the profile code. 1 or 2 is from the db as the example image I've uploaded displays, so the code above has to read one of those numbers of the user logged in. It is that easy I'm sure, but I can't see it.
  20. Html

    user id

    <?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() ; } # On success retrieve user_id, first_name, and last name from 'users' database. if ( empty( $errors ) ) { $q = "SELECT user_id, first_name, last_name FROM users WHERE email='$user_id'" ; $r = mysqli_query ( $dbc, $q ) ; if ( @mysqli_num_rows( $r ) == 1 ) { $row = mysqli_fetch_array ( $r, MYSQLI_ASSOC ) ; return array( true, $row ) ; { echo '<tr><td>' . $row['first_name'] .' '. $row['last_name'] . '<br>'. </td><td>' . </td> </tr>'; } echo '</table>' ; } ?> Still nothing as is, I did try changing the $q to $user_id
  21. Html

    user id

    What..😶 So it was user_id but with the symbol. I learn quite late then.
  22. Html

    user id

    I thought I made some progress with at least getting what I needed, okay the book I have Php 7 in Easy steps has the forum tutorial, there is no $e, that would be in the Mysql book obviously, which I don't have so I can't state what that means, obviously email or what ever, as I got this from the link the other user posted on here, which solved the whole login problem I was having, since I no longer had to workout what to do, and going nowhere with it. Okay, getting back to this, <?php # Access session. session_start() ; # 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 ) ) { $q = "SELECT user_id, first_name, last_name FROM users WHERE id='$id'" ; $r = mysqli_query ( $dbc, $q ) ; if ( @mysqli_num_rows( $r ) == 1 ) { $row = mysqli_fetch_array ( $r, MYSQLI_ASSOC ) ; return array( true, $row ) ; { echo '<tr><td>' . $row['first_name'] .' '. $row['last_name'] . '<br>'. </td><td>' . </td> </tr>'; } echo '</table>' ; } ?> May be this might do it?
  23. Html

    user id

    Okay everyone, I used the code from the site, i don't have a book of that exact code I have used, I thought I mentioned in previous posts, I did, but you folks forgot. I am using the code from the forum of which I have that book to create this profile.php, okay, as shown above. And yes I do agree copying pasting isn't the way to go about creating code to get a task going and done, but for the page setup I used what there was, as for the code from the forum, yes I did copy and paste, for ease, as when I did the first time, I got the spacing wrong which caused errors as well not having the right words, and characters in certain places. As for $e I don't know, that is what the code displays. I will check the php 7 book again.
  24. Html

    user id

    So it is like this, a lot simpler than I thought then.. <?php # Access session. session_start() ; # 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 ) ) { $q = "SELECT user_id, first_name, last_name FROM users WHERE email='$e'" ; $r = mysqli_query ( $dbc, $q ) ; if ( @mysqli_num_rows( $r ) == 1 ) { $row = mysqli_fetch_array ( $r, MYSQLI_ASSOC ) ; return array( true, $row ) ; { echo '<tr><td>' . $row['first_name'] .' '. $row['last_name'] . '<br>'. </td><td>' . </td> </tr>'; } echo '</table>' ; } ?> I did login, and then typed profile.php, nothing is displayed, obviously something with the code, structure problem may be.
  25. Html

    user id

    $q = "SELECT user_id, FROM users WHERE email='user_id'" ; Right, well id is 1, but you are getting at there needs to be some kind of id name for the user_id as is here <?php # Access session. session_start() ; # 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 ) ) { $q = "SELECT user_id, FROM users WHERE email='user_id'" ; $r = mysqli_query ( $dbc, $q ) ; if ( @mysqli_num_rows( $r ) == 1 ) { $row = mysqli_fetch_array ( $r, MYSQLI_ASSOC ) ; } ?> So we need print code in this above, So this below, some of it can be inserted in, $sql = 'SELECT * FROM USERS' ; $result = mysqli_query( $dbc, $sql ) ; if ( mysqli_num_rows( $result ) > 0 ) { echo '<table><tr><th>Posted By</th><th id="id">Mes</th></tr>'; while ( $row = mysqli_fetch_array( $result , MYSQLI_ASSOC )) { echo '<tr><td>' . $row['user_id'] . '</td> </tr>'; } echo '</table>' ; } mysqli_close( $dbc ) ; I took this from the forum code, and made some changes. I don't know where to go from here, with the table removal for a print name?
×