Jump to content

All Activity

This stream auto-updates     

  1. Today
  2. Html

    Remove data

    Sure I posted above, setting, Well if you include not just the php code. <?php ?> <html> <body> <img src="header2018may15.jpg"> <br /> <p><b>User settings</b></p> <form method="POST" action="<?php $_SERVER[ 'PHP_SELF' ] ?>" enctype="multipart/form-data"> Select an image to upload : <input type="file" name="image" > <br /> <br /> <input type="submit" value="Upload Image" > </form> <?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() ; } if( $_SERVER[ 'REQUEST_METHOD' ] == 'POST' ) { $name = $_FILES[ 'image' ][ 'name' ] ; $temp = $_FILES[ 'image' ][ 'tmp_name' ] ; $size = $_FILES[ 'image' ][ 'size' ] ; $ext = pathinfo( $name , PATHINFO_EXTENSION ) ; $ext = strtolower( $ext ) ; if( $ext != 'png' && $ext != 'jpg' && $ext != 'gif' ) { echo 'Format must be PNG, JPG, or GIF' ; exit() ; } if( $size > 512000) { echo 'File size must not exceed 500Kb' ; exit() ; } if( file_exists( $name ) ) { echo 'File '.$name.' already uploaded' ; exit() ; } try { move_uploaded_file( $temp , $name ) ; echo 'File uploaded : '.$name ; echo '<br><img src="'.$name.'">' ; } catch( Exception $e ) { echo 'File upload failed!' ; } } ?> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <img src="bottomheader.jpg"> </body> </html> So below the bottom curly bracket I want to add this new feature so use an image.
  3. Yesterday
  4. justsomeguy

    Remove data

    I am referring to the file you are working on changing.
  5. Html

    Remove data

    That is the complete file, setting.php is there, that above is from home.php, that isn't related to trying to remove a logged in user. It isn't as if that file has anything on removing a user. Perhaps you are referring to the login_tools part, sure that is added in the setting.php page. { require ( 'login_tools.php' ) ; load() ; }
  6. It's not a reserved variable, you overwrote it: $browser = $browser['browser'];
  7. Print $_SERVER['PHP_SELF'] to see what it's set to, use that to figure out what to check for.
  8. justsomeguy

    Remove data

    That's not the same code you posted for the other page. Post the complete file that you're working on, not only part of it.
  9. The following webpage authored by me contains a TopNav and fixed SideNav. The TopNav isn't fixed. So it can scroll. Only the SideNav is fixed at the left. Both Navbars are created using flexboxes. Here's the key CSS: /* Top navigation bar */ .topnav { display: flex; background-color: #777; /* gray */ } /* Side navigation bar */ .sdnav { display: flex; flex-direction: column; width: 200px; height: 100%; position: fixed; overflow: auto; background-color: #f1f1f1; /* light gray */ } And here's the key HTML: <body> <!-- Top Navigation Bar --> <div class="topnav"> <a href="#">Home</a> <a href="#" class="active">News</a> <a href="#">Contact</a> <a href="#">About</a> </div> <!-- Side Navigation Bar --> <div class="sdnav"> <a href="#">What</a> <a href="#" class="active">Where</a> <a href="#">When</a> <a href="#">How</a> </div> <div class="main"> ... </div> </body> A problem occurs when I scroll down. This causes the TopNav to move off the top of the screen (since it isn't fixed). And here's the problem: A gap at the top of the SideNav then appears. Basically the problem occurs since: 1) The TopNav isn't fixed whereas the SideNav is fixed. 2) The SideNav occurs in the markup below the TopNav. One way to solve this problem is to make the TopNav fixed. Then a gap would obviously not appear above the SideNav, since the TopNav couldn't disappear in the first place. Is there any other solution using just CSS? Note: Both Navbars are responsive. The responsive part is working fine. It's just the gap while scrolling that's the problem. Thanks.
  10. I solved this meanwhile by changing the $browser variable into $some_var as I assume $browser is a reserved variable by php
  11. I have browscap installed this way: X:/wamp64/browscap/lite_php_browscap.ini If I use the following code: <?php $browser = get_browser(null, true); var_dump($browser); $brows_par = $browser['parent']; $browser = $browser['browser']; $version = $browser['version']; $platform = $browser['platform']; $dev_type = $browser['device_type']; $mobile = $browser['ismobiledevice']; $tablet = $browser['istablet']; ?> Then I get error messages for the last 5 variable settings error output: and for the other offsets same error message except the first 2. see the image for the var_dump value of $browser what causes the Illegal String Offset warning error message?
  12. ahh, ok i will test it and get back to you! Thanks! One question. If i use the PHP_SELF... does it give the "index.php" or just the "index" name? Thanks in advance tho! EDIT: Okay so i tested it and it does not work properly, maybe me doing it wrong. I am including the file "navbar.php" from location "include/html/GLOBAL/navbar/navbar.php" How should i put it in? If that is the problem that is? Thanks!
  13. ahh, ok i will test it and get back to you! Thanks! One question. If i use the PHP_SELF... does it give the "index.php" or just the "index" name? Thanks in advance tho! :D
  14. Html

    Remove data

    The setting.php page isn't accessible without being logged in due to adding the user_id code as I displayed in the example. And sure the code above is what I'm trying to get to. This is on the home page after logged in, so that is where I thought to use that on the setting as I've stated, <?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' ; # Display body section. echo "<h2>Profile home</h2><p>You are now logged in, {$_SESSION['first_name']} {$_SESSION['last_name']} </p>"; If I remove the if statement, if it doesn't have a purpose for setting page?
  15. Last week
  16. justsomeguy

    Remove data

    I don't think you're understanding what I said. An if statement has 2 parts - the condition, and what to do if the condition is true. if (condition) { do this } Look at your code again. You have the if statement checking if the user ID is in the session, but what does it do if it's not? Look at the code and tell me what it's going to do if the user is not logged in. The comment right before the if statement says to redirect if they're not logged in. But you must have forgotten to add the actual code to redirect them, because the only thing you have is an if statement. The end result of that code is that it will only process the uploaded file if the user is not logged in. That seems like a weird rule. Didn't you say that you wanted a button or link to trigger the delete? That's what your if statement should check for - did they click on that.
  17. Html

    Remove data

    Well, that was how the profile page would of had worked with that, but the way the core files are setup is, the session and user id works by having that so the page visited isn't accessible by typing in the link, it can only be accessed by a registered user. It works for home.php which is after login.php so why not use that? Obviously you sort of understand the plan now. As for the remove data, well I really don't know, I was just thinking may be it can work that way? Should I remove the if statement from the sql code part, if it doesn't work with it then obviously it has to go. As for the example, Alfreds isn't a registered name, so the name or an id number is what is necessary.
  18. The now function returns a date, if that is an integer column then you should use the unix_timestamp function and just subtract the number of seconds.
  19. justsomeguy

    Remove data

    # Redirect if not logged in. if ( !isset( $_SESSION[ 'user_id' ] ) ) What are you doing with that code? You have an if statement there. If that is true, then what happens? All you have is an if statement. The way you have your code structured, PHP considers the if statement which follows that to be whatever you want to do if the above if statement is true. So you are telling it to only process the uploaded file if the user is not logged in. What's the point of that? Are you just copying and pasting bits of code around without knowing what they do? if (empty($errors)) { $q = "DELETE FROM users WHERE $user_id='Alfreds';"; $r = mysqli_query($dbc, $q); Unless a variable called $errors has a truthy value, you're either going to delete every user or no user depending on whether or not $user_id is set to "Alfreds". If it is, then you'll delete every user. And you always run that code unless $errors is set and has a truthy value.
  20. Html

    Remove data

    I added the User_id from the other core file, and that now makes it so that the setting.php page can only be accessible by logging in. So that is sorted. Now the button or link, # On success retrieve user_id, first_name, and last name from 'users' database. if (empty($errors)) { $q = "SELECT post_date, message, comment_user_id FROM forum"; $r = mysqli_query($dbc, $q); $row = mysqli_fetch_array($r, MYSQLI_ASSOC); DELETE FROM table_name WHERE condition; # On success retrieve user_id, first_name, and last name from 'users' database. if (empty($errors)) { $q = "DELETE FROM Customers WHERE CustomerName='Alfreds Futterkiste';"; $r = mysqli_query($dbc, $q); $row = mysqli_fetch_array($r, MYSQLI_ASSOC); Taking from the core file for the user login code, I put this together, probably won't work correctly, but I think this is the correct step. May be the last line isn't necessary. So this would go below the upload code, with a bracket to separate it. } catch( Exception $e ) { echo 'File upload failed!' ; } } # On success retrieve user_id, first_name, and last name from 'users' database. if (empty($errors)) { $q = "DELETE FROM users WHERE $user_id='Alfreds';"; $r = mysqli_query($dbc, $q); $row = mysqli_fetch_array($r, MYSQLI_ASSOC); { ?>
  21. I also solved it for batch files, by removing the parentheses
  22. I made a type mismatch in PHPmyadmin. The ; should not be included inside the double quotes. But still I can't understand the change of : - into a : û in the batch script. What causes this error?
  23. I solved this meanwhile. I used the timestamp column to make the query . I used this query : DELETE FROM `tab` WHERE `timestamp_col` < (NOW()– INTERVAL 10 MINUTE); I works only in the mysql command line interpreter. But I cant get it working in a batch script. Also in phpmyadmin it does not work. The error is in the minus sign. when running the batch script it shows a u with a caret like this û , and phpmyadmin gives error messages. Anyone any idea how to solve this?
  24. Html

    Remove data

    I found this video tutorial on a login system, I don't know much about php, but this looks dated. How ever, he did used an up to date encryption. Claims to be using Mysqli, and PDO or something, could be in date as well some of it out of date. Unfortunately that is all it appears to do. https://youtu.be/LC9GaXkdxF8?t=2346 As for the a remove user link code, it will be the logged in user, like you registered and no longer want to be on the db, it isn't an admin account. Just a regular user. Since the setting.php is a separate page and not related to the login system I have. I may need to add the session_id code that is on the actual login page and logged in subsequent page after. # Access session. session_start() ; # Redirect if not logged in. if ( !isset( $_SESSION[ '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' ] ) ) if( $_SERVER[ 'REQUEST_METHOD' ] == 'POST' ) { $name = $_FILES[ 'image' ][ 'name' ] ; $temp = $_FILES[ 'image' ][ 'tmp_name' ] ; $size = $_FILES[ 'image' ][ 'size' ] ; $ext = pathinfo( $name , PATHINFO_EXTENSION ) ; $ext = strtolower( $ext ) ; if( $ext != 'png' && $ext != 'jpg' && $ext != 'gif' ) { echo 'Format must be PNG, JPG, or GIF' ; exit() ; } if( $size > 512000) { echo 'File size must not exceed 500Kb' ; exit() ; } if( file_exists( $name ) ) { echo 'File '.$name.' already uploaded' ; exit() ; } try { move_uploaded_file( $temp , $name ) ; echo 'File uploaded : '.$name ; echo '<br><img src="'.$name.'">' ; } catch( Exception $e ) { echo 'File upload failed!' ; } } ?> So this is what I think it should be setup like
  25. justsomeguy

    Remove data

    Of course it's possible. Like the page on deleting shows, if you want to delete a particular row in the database you need to be able to uniquely identify that row in the SQL query. So, pass whatever unique identifier you're using to a page that can get the ID and delete the corresponding row. You can put the ID in the link in the button if you want to, or create a form and pass it that way (a dropdown to select a user to delete, or however else you want to do it). I wouldn't recommend using that file upload code, the $_FILES array contains an error code which the code above doesn't check. http://php.net/manual/en/features.file-upload.post-method.php http://php.net/manual/en/features.file-upload.errors.php
  26. Html

    Remove data

    Sure, well that example is from the book I have, that was how I got what I have, and the other files were from the site, which is from another book, which donesuk found, I think now. I simply want to add to that php code, a remove data feature, a button which actives removing a logged in user from the db, isn't that possible? As you can understand, it is a setting page so upload feature and a remove button is now what I want to add. I had tried with a user on here to get a profile page using existing code, but that unfortunately didn't work, I don't know, the code just messes up when new code is added so it was a nice try, but it didn't work out. I probably need custom code for a user site system. But for the moment, what I have works and is better than what i had used before, which was the junk from the youtube video. So this code above needs $user_id tagged in, so the remove feature would know that the user Bob or what ever is logged in and is then removed. Where do I go with this, I looked at the W3schools, and read a few pages, but I'm not sure. What can you hint to me or suggest?
  27. An SQL command given that you already have the unix time stored in another variable would be quite simple. DELETE FROM table WHERE time < ? As long as you've inserted these records with their related timestamp, this should remove everything that has a timestamp less than the value you set. The value can be calculated as <?php $criteria = time() - 3600; //3600 seconds is 1 hour ?>
  28. Its a good point of reference, but most of the time I just answer questions in this forum. With the occasional question of my own.
  1. Load more activity
×
×
  • Create New...