Jump to content

Html

Members
  • Posts

    640
  • Joined

  • Last visited

Everything posted by Html

  1. Hmm, okay. What about the mysql code that is needed for a specific id? What I have there is for only a column? Not an actual user which is logged in. In the W3schools, there is no example section on that?
  2. Okay here is the example code as is, So the sql line isn't enough to change to get the logged in user's messages to display only on the forum.php so that is a profile page. It isn't public since it requires only logged in use to view that forum, but it is close enough for now. forum.php?=1 or something, profile.php? <?php # DISPLAY COMPLETE FORUM 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 = 'Forum' ; include ( 'includes/header.html' ) ; # Open database connection. require ( '../connect_db.php' ) ; # Display body section, retrieving from 'forum' database table. $q = "SELECT * FROM forum" ; $r = mysqli_query( $dbc, $q ) ; if ( mysqli_num_rows( $r ) > 0 ) { echo '<table><tr><th>Posted By</th><th>Subject</th><th id="msg">Message</th></tr>'; while ( $row = mysqli_fetch_array( $r, MYSQLI_ASSOC )) { echo '<tr><td>' . $row['first_name'] .' '. $row['last_name'] . '<br>'. $row['post_date'].'</td> <td>' . $row['subject'] . '</td><td>' . $row['message'] . '</td> </tr>'; } echo '</table>' ; } else { echo '<p>There are currently no messages.</p>' ; } # Create navigation links. echo '<p><a href="post.php">Post Message</a> | <a href="shop.php">Shop</a> | <a href="home.php">Home</a> | <a href="goodbye.php">Logout</a></p>' ; # Close database connection. mysqli_close( $dbc ) ; # Display footer section. include ( 'includes/footer.html' ) ; ?>
  3. So the example code is meaningless if edit a snippet of it, because I don't full understand anything about php? That example code is functioning in the user site I have setup. The whole thing was loaded in and bang, done, I've only tried to edit and add to it. Obviously I can't get the function working, so I'm now looking back at trying to display the message from the logged in user on it's own. Just where are the syntax errors, this is the complete code?
  4. Are you referring to $user_id being in black, instead of green like the others. Is it to with the "." and so on? That is all I have changed, just so you know this is exact copy from the source files. $q = "SELECT * FROM forum WHERE id="$user_id" ; It will need a where, as forum alone only displays all messages, so WHERE clause will be needed for the current logged in user viewing the forum.php quite obvious. forum.php is the profile index for any logged in user.
  5. I sent an email to a user on the youtube site who produces tutorials, see what that person has to state about the code. I am not sure what I am going to do if I can get this code working. I also want to have a post message to the profile index, still haven't got that working yet, change password, upload an image to the user profile. And remove data is one of them, as well a directory of new users created, and an inbox and outbox system, and that would be it. So far it is only register, and login using the example code, and using the example code forum. I tried to modify that to display on the logged in user's message. Instead of just all of them who ever posts to a public forum/display message page. <?php # DISPLAY COMPLETE FORUM 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 = 'Forum' ; include ( 'includes/header.html' ) ; # Open database connection. require ( 'connect_db.php' ) ; # Display body section, retrieving from 'forum' database table. $q = "SELECT * FROM forum WHERE id="$user_id" ; $r = mysqli_query( $dbc, $q ) ; if ( mysqli_num_rows( $r ) > 0 ) { echo '<table><tr><th>Posted By</th><th>Subject</th><th id="msg">Message</th></tr>'; while ( $row = mysqli_fetch_array( $r, MYSQLI_ASSOC )) { echo '<tr><td>' . $row['first_name'] .' '. $row['last_name'] . '<br>'. $row['post_date'].'</td> <td>' . $row['subject'] . '</td><td>' . $row['message'] . '</td> </tr>'; } echo '</table>' ; } else { echo '<p>There are currently no messages.</p>' ; } # Create navigation links. echo '<p><a href="post.php">Post Message</a> | <a href="shop.php">Shop</a> | <a href="home.php">Home</a> | <a href="goodbye.php">Logout</a></p>' ; # Close database connection. mysqli_close( $dbc ) ; # Display footer section. include ( 'includes/footer.html' ) ; ?> I haven't a clue if that alone would do this, it can't be that difficult compared to a function delete.🤔
  6. I'm no where near there then, besides that is PDO or what ever, I am using php 5. Considering php & Mysql was published in 2012. That code is more useful for if I attempt to learn php 7 from scratch.
  7. Result mode, so now there is more than one mysqli_query to be used, This is certainly new to me.🤨 Yeah. Now what.😕
  8. <?php # Access session. session_start() ; # Connect to the database. require ('connect_db.php') ; { deleterecord(); // call the function function deleteRecord( $dbc, $q, $r , $user_id) $q = 'DELETE * FROM users WHERE id' = '$user_id'; $r = mysqli_query( $dbc , $q, $user_id ) ; } # Close database connection. mysqli_close( $dbc ) ; ?> Okay, I am probably not going anywhere with this.
  9. I wonder whos head that will be.😕
  10. I don't know why I am not using user_id, I haven't a clue. <?php # Access session. session_start() ; # Connect to the database. require ('connect_db.php') ; { deleterecord(); // call the function } function deleteRecord( $dbc, $q, $r ) { $q = 'DELETE * FROM users WHERE id = $user_id'; $r = mysqli_query( $dbc , $q ) ; } # Close database connection. mysqli_close( $dbc ) ; ?>
  11. 😑 Yeah sure is. <?php # Access session. session_start() ; # Connect to the database. require ('connect_db.php') ; deleterecord(); // call the function function deleteRecord( $dbc, $q, $r ) { $q = 'DELETE * FROM users WHERE id = $user_id'; $r = mysqli_query( $dbc , $q ) ; } # Close database connection. mysqli_close( $dbc ) ; ?>
  12. { deleterecord(); // call the function function deleteRecord( $dbc, $q, $r ) $q = "DELETE * FROM users WHERE id = '$user_id'" ; $r = mysqli_query( $dbc , $q ) ; }
  13. Right, This is a function from the Php & Mysql code example. <?php # Create a global variable. $result = 5 + 5 ; function square() { $result = 5 * 5 ; echo "Local Square Result = $result<br>" ; } function cube() { $result = 5 * 5 * 5 ; echo "Local Cube Result = $result<br>" ; } echo "Global Sum Result = $result<br>" ; square(); cube(); ?>
  14. Ineasysteps has a website, but have no customer support, but a person can send recommendations, so that was what I did end of last month, I sent the code here, and hopefully the work was mostly done, even though it didn't make much sense. I tried the book, it is too much in it. I looked back at php 7 book from ineasysteps on functions, I then looked back at the w3schools example, so I'm confused on all of it. One example states this, and then another. <?php # Access session. session_start() ; # Connect to the database. require ('connect_db.php') ; { deleterecord(); // call the function function deleteRecord( $dbc, $q, $r ) $q = 'DELETE * FROM users WHERE id = $user_id'; $r = mysqli_query( $dbc , $q ) ; } # Close database connection. mysqli_close( $dbc ) ; ?> Updated this, no rows. W3 schools first example write message, so I wasn't sure what is where.
  15. Perhaps, the book is pretty basic, the one I have, ineasysteps is the name, it doesn't really give a solid understanding of php. Cheaper books won't be that in depth. <?php # Access session. session_start() ; # Connect to the database. require ('connect_db.php') ; function deleteRecord( $dbc ) { $q = 'DELETE * FROM users WHERE id = $user_id'; $r = mysqli_query( $dbc , $q ) ; $num = mysqli_num_rows( $r ) ; if ( $num > 0 )' } deleterecord(); // call the function # Close database connection. mysqli_close( $dbc ) ; ?> if ( $num > 0 )' <?php # Access session. session_start() ; # Connect to the database. require ('connect_db.php') ; function deleteRecord( $dbc ) { $q = 'DELETE * FROM users WHERE id = $user_id'; $r = mysqli_query( $dbc , $q ) ; $num = mysqli_num_rows( $r ) ; if ( $num > 0 ) deleterecord(); // call the function } # Close database connection. mysqli_close( $dbc ) ; ?> No problem with this in php checker. <?php # Access session. session_start() ; # Connect to the database. require ('connect_db.php') ; function deleteRecord( $dbc, $q, $r ) { $q = 'DELETE * FROM users WHERE id = $user_id'; $r = mysqli_query( $dbc , $q ) ; $num = mysqli_num_rows( $r ) ; if ( $num > 0 ) deleterecord(); // call the function } # Close database connection. mysqli_close( $dbc ) ; ?>
  16. Yeah, i guess, and sure I thought about that in the past, but I just felt I had to keep going with this example code to try and get what I wanted working. Like I stated, I emailed the company who published the book, and they didn't respond to trying to make sense of my example code. Not sure what is going on there, could be that the book is too old for anyone there to want to add a tutorial on removing data. Seems obvious to include that with a user site login, I am sure everybody here thinks that is a must. <?php # Access session. session_start() ; # Connect to the database. require ('connect_db.php') ; function deleteRecord( $dbc ) { $q = 'DELETE * FROM users' WHERE id = '$user_id'; $r = mysqli_query( $dbc , $q ) ; $num = mysqli_num_rows( $r ) ; if ( $num > 0 ) } deleterecord(); // call the function # Close database connection. mysqli_close( $dbc ) ; ?> I don't know.
  17. Unfortunately, I was like with this python and visual basic. Your post reminds me of when I had tried to this, I seem to switch off on the learning curve. I did try the php 7 book by ineasysteps, it wasn't all that, just code really that works, very basic explanation. The book you suggested is much more thick with explanation, but I couldn't quite get it.
  18. There is a lot there on the functions. The first one seems pretty basic, and useless the rest go onto something else. I thought the SQL line was correct? So now it isn't. 🙄 So what, there is no longer the use for WHERE?
  19. Well, I got my source from the youtube site, no where else. One video shows one example, and then another. So I just tried what there was. So what is the step to get the function going then?
  20. The last two no. The first and second, The first is the sql line the variable is instructed to remove the logged in user from the id column. And the second line is the database connection and the variable part of the mysqli function. Not sure what else.
  21. function deleteRecord( $dbc ) That is the function declared Then the opening brace following, the sql line, and then rest is rows and connection as well the $q variable that is a part of the example code consistency, a closing brace, that is that at its bare bones. Not sure if that part is even necessary. $num = mysqli_num_rows( $r ) ; if ( $num > 0 ) { $q = 'DELETE * FROM users' WHERE id = '$user_id'; $r = mysqli_query( $dbc , $q ) ; $num = mysqli_num_rows( $r ) ; if ( $num > 0 ) }
  22. As I have tried before, I viewed the youtube clips that is where I have got any idea on this code. According to the example, which is different from the code example from the Php & Mysql example code. <?php # Access session. session_start() ; # Connect to the database. require ('connect_db.php'); function deleteRecord( $dbc ) { $q = 'DELETE * FROM users' WHERE id = '$user_id'; $r = mysqli_query( $dbc , $q ) ; $num = mysqli_num_rows( $r ) ; if ( $num > 0 ) } # Close database connection. mysqli_close( $dbc ) ; ?>
  23. Yeah, short fuse guy. <?php # Access session. session_start() ; # Connect to the database. require ('connect_db.php'); function deleteRecord( $dbc ) { $q = 'DELETE * FROM users' WHERE id = '".$user_id."'"; $r = mysqli_query( $dbc , $q ) ; $num = mysqli_num_rows( $r ) ; if ( $num > 0 ) } # Close database connection. mysqli_close( $dbc ) ; ?> This is correct to use? The problem appears to be with the sql line, as it has been. There is ten quotes, three of them are speech marks as we have here " ' " ' FROM users etc' = ' " The original code, I copied from one of the example files, I thought I was onto something by putting together what I have. I'm all over the place with this. I logged into the free web host, I was lucky, no hardware failure affected the mysql db, it did on two other servers. I tried this $q = 'DELETE * FROM users' WHERE id ="'".$user_id."'"; So two speech marks, and one quote, in the code the $user_id turned blue, in the ftp editor. That hasn't changed anything.
  24. Okay, well delete is what is the keyword to use for the sql, obviously. Well, I don't know what more the code requires, I am basing it off from videos, and just got the idea to edit the code to include what the example code has. I may not be going the correct way, but I'm close to completing this. As for the quotes, I took the code as is from the example code, so it should be perfectly fine, just needs a row name, which is user_id So now what is next? Does it need more code or just editing what is there? <?php # Access session. session_start() ; # Connect to the database. require ('connect_db.php'); function deleteRecord( $dbc ) { $q = 'DELETE * FROM users' WHERE id = '".$user_id."'"; $r = mysqli_query( $dbc , $q ) ; $num = mysqli_num_rows( $r ) ; if ( $num > 0 ) } # Close database connection. mysqli_close( $dbc ) ; ?>
  25. So the second requires ten single quotes? The sql line being $q = 'SELECT * FROM users' WHERE id ='".$user_id."'"; And delete not select. Well I thought select would be fine, considering the function is a delete one, so this should remove a user logged into the site, from the mysql db? <?php # Access session. session_start() ; # Connect to the database. require ('connect_db.php'); function deleteRecord( $dbc ) { $q = 'DELETE * FROM users' WHERE id = '".$user_id."'"; $r = mysqli_query( $dbc , $q ) ; } # Close database connection. mysqli_close( $dbc ) ; ?> This is okay even without the rows bit of code. Either way, the code doesn't remove the logged in user from the db of the id column. <?php # Access session. session_start() ; # Connect to the database. require ('connect_db.php'); function deleteRecord( $dbc ) { $q = 'DELETE * FROM users' WHERE id = '".$user_id."'"; $r = mysqli_query( $dbc , $q ) ; $num = mysqli_num_rows( $r ) ; if ( $num > 0 ) } # Close database connection. mysqli_close( $dbc ) ; ?>
×
×
  • Create New...