Jump to content

Html

Members
  • Posts

    640
  • Joined

  • Last visited

Everything posted by Html

  1. Html

    Remove data

    I decided to take a glance at the book Php 7 In easy steps, There is a catching exceptions example in it, how ever I don't quite get that. The example is more descriptive than the php manual. <?php function check_size( $num ) { if( $num < 10 ) { throw new Exception( "Number : $num<br>Value must exceed 10" ) ; } } try { check_size( 5 ) ; } catch( Exception $e ) { echo '<b>Size Exception!</b><br>'.$e->getMessage().'<hr>'; } class CustomException extends Exception { public function get_details() { $details = 'File : '.$this->getFile(). '<br>Line : '.$this->getLine(). '<br>'.$this->getMessage(); return $details ; } } function check_parity( $num ) { if( $num % 2 !== 0 ) { throw new CustomException( "Number : $num<br>Value must be even" ) ; } } try { check_parity( 5 ) ; } catch( CustomException $e ) { echo '<b>Parity Exception!</b><br>'.$e->get_details().'<hr>'; }
  2. Html

    Remove data

    function deleteRecord(mysqli $dbc, $user_id){ $sql ="DELETE FROM 'users' WHERE id ='".$user_id."'"; $result = $db->query($sql); if(!result){ throw new Exception( message 'Cannot delete' ); } } function deleteRecord(mysqli $dbc, $user_id){ $sql ="DELETE FROM 'users' WHERE id ='".$user_id."'"; $user_id = 1; try{ throw new Exception('cannot delete.'); }catch(Exception $q){ return $user_id; $user_id--; // this line will be ignored }finally{ $bar++; } } echo deleterecord(); // 2 I don't quite know, this going anywhere?🤨
  3. Html

    Remove data

    I tried looking at the 3, 4, 5, not to sure on those. Then code 1 in the comment section below. <?php function foo(){ $bar = 1; try{ throw new Exception('I am Wu Xiancheng.'); }catch(Exception $e){ return $bar; $bar--; // this line will be ignored }finally{ $bar++; } } echo foo(); // 2 ?>
  4. Html

    Remove data

    Is the code example there, the correct way? I am uncertain on what to do next. The example there is much longer, and the description there doesn't quite help me solve this.
  5. Html

    Remove data

    I did, and this was what is listed, http://php.net/manual/en/class.exception.php How that example sort of works with what I have, I really don't know.
  6. Html

    Remove data

    I remembered to check a phpcodechecker site, <?php # Connect to the database. require ('connect_db.php'); # Access session. session_start() ; function deleteRecord(mysqli $dbc, $user_id){ $sql ="DELETE FROM 'users' WHERE id ='".$user_id."'"; $result = $db->query($sql); if(!result){ throw new Exception( message 'Cannot delete' ); } } ?> Still gives ''Cannot delete'' (T_CONSTANT_ENCAPSED_STRING) in your code on line 13
  7. Html

    Remove data

    I did add the error code, as for the syntax, the page still doesn't display anything even with the error code. So the function code is broken.
  8. Html

    Remove data

    Hmm, okay, so I'm in the correct direction then. I was only going from the tutorial, what I could sort of picture, and understand to try and get what I wanted working. So then, to run this function and sort out the errors where do I go from here?
  9. Html

    Remove data

    <?php # Connect to the database. require ('connect_db.php'); # Access session. session_start() ; function deleteRecord(mysqli $dbc, $user_id){ $sql ="DELETE FROM 'users' WHERE id ='".$user_id."'"; $result = $db->query($sql); if(!result){ throw new Exception( message: 'Cannot delete'; } } ?> This is the code for the remove.php link on the setting page, it doesn't do anything, so the code is sloppy or incomplete in someway. I did add the $user_id as that is what it is in the table. I tried replacing the $user_id with $q as that is listed in other files. I kept the $user_id for the Where part of that code. I also added c to db, that is how it is in the other files of the login files. And his is the simple link on setting.php <a href="remove.php"><img src="remove.jpg"></a> <br /> <br /> <br />
  10. Html

    Remove data

    The setting page has two features, one of them is the link as stated more than one, so I can just use hyperlink code as an image to activate the SQL. Sure I learnt the hyperlink code more than fourteen years ago, something I never forgot, I didn't know about the image code for a form submit button. I am only going on from the tutorial, so the remove.php is what you are getting at, needs to have the function code? I added the code into remove.php, I think I may of got it to work, just need the link in the setting.php page to activate it.
  11. Html

    Remove data

    No I want the link on the same page which I have displayed above, the setting page as is, doesn't work with that code I added below the upload image code. Here is the up to date page. <?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!' ; } } function deleteRecord(mysqli $dbc, $id){ $sql ="DELETE FROM 'users' WHERE id ='".$id."'"; $result = $db->query($sql); if(!result){ throw new Exception( message: 'Cannot delete'; } } ?> <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> <br /> <br /> <input type="image" src="remove.jpg" alt="Remove"> <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> I don't know what the problem could be, may be no $q variable could be the reason since that is part of the core files code. But I honestly not quite sure. As for the link, I don't know how to quite do that, I put that above as I stated, so not sure how to get this working. The remove.php which I did create, but you're probably thinking that isn't needed? I based this off the youtube clip. <?php # Connect to the database. require ('connect_db.php'); # Access session. session_start() ; $id ?> This isn't needed.
  12. Html

    Remove data

    The narrator has five pages, select, delete, db, so it is a page with listings and the code is about removing one or any of them using a link next to them. I obviously want that but for the logged in user, so the code must remove user with id 1. And not id 2 of another user. So the code above is a step in the right direction, it is after the remove.php I must create, but to get that image to go to the remove.php <input type="image" src="remove.jpg" alt="Remove">
  13. Html

    Remove data

    Sure, moved the code. I did find a php/sql video on removing data from a web page connected to a db on youtube. I haven't tried the example, it is narrated well I guess. PHP MYSQL Tutorial 4 | How To Delete A MYSQL Row In PHP - YouTube As for getting what I want, could this clip be fine to get what I need going, using what I have above. Having watched it again, at six minutes, the narrator explains how to remove a list or id entry from the db, so I've started below the curly bracket, 'function deleteRecord' I of course will want to use an image for the link to do this. He used a simple html button for the page. He used an id as variable, the obvious ones in the example code is $q and just the row and dbc connection listed. That was a problem with trying to get the profile page working, it needed that variable. <?php 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!' ; } } function deleteRecord(mysqli ?> <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> <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 I made a start of adding this video tutorial's code, and as for adding an image, I left that incomplete, not sure where to go with this, may be it needs a form code tag. <?php 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!' ; } } function deleteRecord(mysqli $dbc, $){ $sql ="DELETE FROM '' WHERE id ='".$."'"; $result = $db->query($sql); ?> <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> <br /> <input type="image" name"image"> <input type="image" src="remove.jpg" alt="Remove"> <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> an If statement i guess is what is below $result if(!result){ throw new Exception( message: 'Cannot delete' } } so after that, the narrator goes to another page delete.php so that is connected with the button. So I guess remove.jpg goes to a remove.php which contains some more code to complete the task.
  14. 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.
  15. 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() ; }
  16. 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?
  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. 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); { ?>
  19. 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
  20. 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?
  21. Html

    Remove data

    The image upload feature is not connected with removing a logged in user. I want to add the remove feature as an extra, on this setting page.
  22. Html

    Remove data

    Hi, I just wanted some thoughts, out of these examples, what would the best choice to add to this code I have, which is code example from a book php In Easy steps <?php 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!' ; } } ?> https://www.w3schools.com/php/php_mysql_delete.asp So I can tuck in a user_id code for this particular page, and have a button to remove the logged in user instantly or within a time frame. Thanks
  23. Thanks for the responses, Well I used the old one. I guess it shouldn't be a problem. Nice addition to the page I have.
  24. Hello, I have this basic form submit button on my page, like to register on the db, how do I change the submit button to an image as an alternative? <form action="index.php" method="post"> <p>First Name: <input type="text" name="first_name" size="20" value="<?php if (isset($_POST['first_name'])) echo $_POST['first_name']; ?>"> Last Name: <input type="text" name="last_name" size="20" value="<?php if (isset($_POST['last_name'])) echo $_POST['last_name']; ?>"></p> <p>Email Address: <input type="text" name="email" size="50" value="<?php if (isset($_POST['email'])) echo $_POST['email']; ?>"></p> <p>Password: <input type="password" name="pass1" size="20" value="<?php if (isset($_POST['pass1'])) echo $_POST['pass1']; ?>" > Confirm Password: <input type="password" name="pass2" size="20" value="<?php if (isset($_POST['pass2'])) echo $_POST['pass2']; ?>"></p> <p><input type="submit" value="Register"></p> </form> <a href="login.php"><img src="login.jpg"></a> So <input type and so on, so like below is a login page and has the image button, I want that for registration. Thank you.
  25. <?php // the message $msg = "First line of text\nSecond line of text"; // use wordwrap() if lines are longer than 70 characters $msg = wordwrap($msg,70); // send email mail("someone@example.com","My subject",$msg); ?> And what exactly is this? How could that work with what I have above, or it wouldn't work.
×
×
  • Create New...