Jump to content

Remove data


Html

Recommended Posts

The current code is this,

And yes I am still on this, fortunately, I made progress with removing my header image I had on the index page, a couple of others, and replaced it with CSS code🙂 Now that is a first, I had a book years ago on that, I never understood CSS. I am trying to remember what it is called, but I can't think of it. From 2006.

So that will save some bandwidth.

As for the function code this is still what I have got. The videos show two different ways of doing a function, so I don't know what is wrong or right with what I have.😩

Neither narrators responded to my query with example code.

 

<?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('Cannot  delete' );

     }
}
?>

That is remove.php When I click on this from the image link, only a blank screen then loads, so it doesn't work. The logged in user isn't removed from the db instantly, I will want to add a timer to three days after remove.php has been clicked.

Link to comment
Share on other sites

  • Replies 56
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Posted Images

That is remove.php When I click on this from the image link, only a blank screen then loads, so it doesn't work.

It's doing exactly what you're telling it to do.  You include a file, then start the session, then define a function.  That's all you have it doing.  Perhaps next you want to actually run the function instead of only defining it.  Even if you did, the page would still be blank because you're not telling it to do anything that would write anything to the page.  So, it's doing exactly what you're telling it to do.  It's not going to read your mind and determine what you want to happen and do that, it's going to do exactly what you tell it to.  It's your job to figure out how to tell it to do what you want it to do.  If you want it to print something on the page, then tell it to do that.

Link to comment
Share on other sites

Right...

But the code I got from the clips, if it works in them, why doesn't the example work for my system/host environment. You mentioned define, then the php manual, which has some examples of defining, I posted a few on the previous page.

I don't quite know where to go with this?

function deleteRecord(mysqli $dbc, $user_id){

 

<?php
function deleterecords( $user_id )
{
  if( $user_id < 0 )
  {
     throw new Exception( "cannot delete" ) ;
  }
}
try
{
  user_id( 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 ;
   }
 }

Not sure.

Link to comment
Share on other sites

But the code I got from the clips, if it works in them, why doesn't the example work for my system/host environment.

You're literally not telling the code to do anything.  The code is "working" perfectly, it's doing exactly what you told it to do.  You just didn't tell it to do much other than define a function.

I don't quite know where to go with this?

Well, you need to understand functions, so pick up your book and read the chapter about functions.  If there are chapters before that one that you haven't read, then read those first.  If you pick up a novel and the first thing you read is chapter 9, then you peruse chapter 17, then read the last chapter, then watch a video of someone talking about what they thought of it, you may be able to have a shallow discussion about the book but you're not really going to understand what it's about.  This is no different.  You have no concept of the very basics of the language that you're trying to use and it should be blatantly obvious with how much time you've spent and how little you understand that your methods of learning are completely ineffectual.  You need to start at the beginning of the book and go from there.  If you finish a chapter and you don't really understand what you just read, read it again.  Repeat until you understand.

Link to comment
Share on other sites

If I am honest, there is a lot there, and good some of it doesn't appeal to me, I'm going directly to what I need, and want. May be a rubbish way of learning this, but that is how I have gone about this.

Sure there is a chapter in the In Easy steps book I have php 7. The functions I pasted the code from the source files from the series site, but other than what it expresses, I don't fully understand how it relates to my example. I'm not sure how reading other chapters helps this task alone.

I get you're point on learning the basics, I haven't done that, I've taken short cuts. I have had a annoying and tiring time with this, I then decided on example code, since it works, and I was going to take a long time to get anywhere, it hasn't worked out.

Link to comment
Share on other sites

Quote

If I am honest, there is a lot there, and good some of it doesn't appeal to me, I'm going directly to what I need, and want. May be a rubbish way of learning this, but that is how I have gone about this.

Yeah, it is.  You want to build a house.  But you really only like electrical, you're not really into framing and pouring concrete and plumbing and whatever else, that doesn't appeal to you.  So you just toss up some boards so you can do your wiring and electrical, and you're wondering why the roof keeps falling and you have no running water.  You don't want to actually learn how to frame the house, you just want someone to tell you how to keep the roof up.  It doesn't really work like that.

Quote

I then decided on example code, since it works, and I was going to take a long time to get anywhere, it hasn't worked out.

That's because you don't understand why and how the code works.

There is not a single person alive creating functional programs by themselves who does not understand why and how the code works.  You're trying to be the first.  It's not working out.

Link to comment
Share on other sites

  • 5 months later...
On 3/11/2019 at 5:39 PM, Html said:

The current code is this,

And yes I am still on this, fortunately, I made progress with removing my header image I had on the index page, a couple of others, and replaced it with CSS code🙂 Now that is a first, I had a book years ago on that, I never understood CSS. I am trying to remember what it is called, but I can't think of it. From 2006.

So that will save some bandwidth.

As for the function code this is still what I have got. The videos show two different ways of doing a function, so I don't know what is wrong or right with what I have.😩

Neither narrators responded to my query with example code.

 


<?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('Cannot  delete' );

     }
}
?>

That is remove.php When I click on this from the image link, only a blank screen then loads, so it doesn't work. The logged in user isn't removed from the db instantly, I will want to add a timer to three days after remove.php has been clicked.

# Function to create and execute a MySQL query.
function show_records( $dbc )
{
  $q = 'SELECT * FROM watches' ;
  $r = mysqli_query( $dbc , $q ) ;
  $num = mysqli_num_rows( $r ) ;
   if ( $num > 0 )
  {

This may be the edit the code I tried in the past requires, from an example I viewed in the files.

function deleteRecord(mysqli $dbc, $user_id){
$sql ="DELETE FROM 'users' WHERE id ='".$user_id."'";
$result = $db->query($sql);
if(!result){

 

function deleteRecord( $dbc )
{
  $q = 'SELECT * FROM users' WHERE id ='".$user_id."'";
  $r = mysqli_query( $dbc , $q ) ;
  $num = mysqli_num_rows( $r ) ;
   if ( $num > 0 )
  {

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...