Jump to content
Html

Does a remove record link require a particular link?

Recommended Posts

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.🤔

Share this post


Link to post
Share on other sites
Quote

I am not sure what I am going to do if I can get this code working.

You can't do anything if you don't know what you're doing.  So your options are to hire someone to build your site, find someone willing to build you a site for free, or start over at the beginning and actually learn the language.  If you can't detect basic syntax errors then you are not capable of doing this yourself.  Look at the code you posted above, it's highlighting the syntax in the first half and then everything is just green.  Does that look right?  Of course not, because you have a syntax error.

 

Quote

it can't be that difficult compared to a function delete.

 

Not a single thing you're doing is difficult to someone who understands the language.  Like I said, it's like any other language spoken by people.  If you know the language, then saying what you want to say is easy.  But your code might as well be written in Swahili, if you don't understand the language in the first place then of course you can't do anything with it.  I've told you this over and over.  It's not going to change. 

If you don't know the language, none of this will make sense to you.  If you do know the language, then what you're trying to do is very easy.  It's only hard for you because you never bothered to learn the actual language.  You're just buying a book written in Swahili and assuming you can read random paragraphs to get people to know what you're talking about.  That's not how it works.

And watching a video of some random guy speaking Swahili isn't going to change that.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

The SQL code doesn't matter, this isn't about SQL.  You're just defining a string in PHP, it doesn't matter if that's a string of SQL code or any other arbitrary text.  The problem is that you're not following the basic rules of defining strings in PHP.  Your problem is that you don't know what the error is.

Quote

That is all I have changed, just so you know this is exact copy from the source files.

Just so you know, whether or not the code was copied from here or there or anywhere else means not a goddamn thing if there's a syntax error in it.  What are you going to tell the PHP interpreter?  "But I copied it from somewhere else."  OK, go see if PHP cares where you copied the code from.  Tell PHP that you sent an email to some random guy who publishes videos on Youtube to try and make an extra buck, see if the PHP interpreter cares about that.

Share this post


Link to post
Share on other sites

It sounds like you're still somehow trying to justify not knowing the language.  Or that you don't need to know the language because you're just copying code.  It doesn't matter.  You either know the language, or you don't.  If you don't, then forget trying to build a site.  If you want some sort of proof for my claim that you can't do this without knowing the language, I've got several dozen of your forum posts to point you towards.

Share this post


Link to post
Share on other sites

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?

Edited by Html
Where is the syntax errors?

Share this post


Link to post
Share on other sites

So the example code is meaningless if edit a snippet of it, because I don't full understand anything about php?

The problem you run into over and over and over and over again is that your edit introduces some minor syntax error which stops everything from working, and you are unable to detect those errors or make sense of error messages because of your lack of understanding of the language.

Share this post


Link to post
Share on other sites

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' ) ;

?>

 

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites

What about the mysql code that is needed for a specific id?

What about it?

In the W3schools, there is no example section on that?

Yes there is, it shows how to delete one or more records that match a certain value (like an ID), and how to delete all records.

https://www.w3schools.com/sql/sql_delete.asp

Share this post


Link to post
Share on other sites

DELETE FROM Customers WHERE CustomerName='Alfreds Futterkiste';

This?  That isn't an id as such, id would be like 2, 3.

Share this post


Link to post
Share on other sites

"id" is just another field, just like CustomerName. They're all just fields in the database. DELETE works equally well whether you filter using strings or numbers.

Share this post


Link to post
Share on other sites

This?  That isn't an id as such, id would be like 2, 3.

And, just to be clear, you are unable to extrapolate any example that you see that is not related to your specific and exact situation, correct?  Because you don't bother to understand what they're talking about, you only look at example code and think that you're going to somehow gain some sort of knowledge just by looking at code enough.  Is that right?  When the syntax is like this:

DELETE FROM table WHERE column = value

You look at that, and you can't see how it applies to you, because your table name isn't italic table, and your column name is not italic column, and the value you're looking for is "an ID", and not italic value, right?  So it must not apply to your situation, and your situation must use some sort of completely different DELETE query that you cannot manage to find a single example of, and none of the other DELETE queries apply to you because you're using "an ID."

Is all of that about right in terms of how you're looking at this?

Share this post


Link to post
Share on other sites

This can't be real, this has to be a set up.

"How do I unlock a door?"

"Well, I'll show you, look, here's my door.  I get my key out of my pocket, put it in the lock, turn it, and the door is unlocked."

"I don't understand, because even though my door also has a lock and looks similar, and I have a key that more or less looks like yours, since you showed me with YOUR key and YOUR lock, I don't understand at all how that applies to my door."

This is an attempt to see how much of our time you can waste, isn't it?

I feel like you would watch a video of someone showing how to play a certain song on a piano, but it wouldn't make sense because the person played it on their piano in their house and not your piano in your house.

I feel like you would watch a video of how to remove a bolt but it wouldn't make sense because they're not using your wrench.

Share this post


Link to post
Share on other sites

I thought you'd eventually see what I am seeing, you are partly correct, I chase after specific examples to get what I need, I can't go from A-Z. Sure I found a few examples on different sites on sunday, and I tinkered with it. And it worked, if I had done this six months ago, I wouldn't of been here, at least not yet.🙄

 

Share this post


Link to post
Share on other sites

If you're unable to look at the many, many examples out there of delete queries and apply them to your situation, then that's a failure on your part that you need to work on.  I don't understand the reason for that, and I don't understand the solution.  It sounds to me, again, like you skip any discussion about the meaning of anything and just look at code examples.  That is not how to learn.  If you think all of the watered-down tutorials and examples that you're looking through are too complicated or abstract, consider the official documentation:

https://dev.mysql.com/doc/refman/8.0/en/delete.html

In case it's not obvious, you're wrong.  The examples that you see DO apply to your situation, due to the fact that every delete query follows the same basic structure.  The fact that you see a query that has a WHERE condition that compares a column with a string, and you have absolutely no idea how to translate that to a WHERE condition that compares a different column with a number, is a failure on your part to understand anything that you're doing.  Understanding is not and never has been your goal, you want to skip to the end and think that programming is the one trade in the entire world where you can skip the necessary knowledge and manage to still produce a functional product.  I have absolutely no idea where you got that idea from, but it too is wrong.

I don't know how many times you need to hear this, but obviously "several dozen" is too few for some reason.

Quote

I can't go from A-Z.

Why not?  What makes you unique to everyone else who has tried?  Is there a learning disability or something that we're not aware of?  Because if you have a learning disability, and you're asking for help, that's knowledge that the people helping you need.

Share this post


Link to post
Share on other sites

I didn't do with with maths and language, when I was in education. I think I mentioned this before in a previous topic. So there is a repeating pattern.

There have been many people who have tried php and mysql, and never got far with it. I have managed to stick with it, even though I am all over the place with this.

Share this post


Link to post
Share on other sites

I have managed to stick with it

I wouldn't say that.  You have repeatedly had your mistakes pointed out to you, especially in the learning process, and you have not made an attempt to correct or learn from those mistakes.  I have repeatedly told you to start at the beginning and not skip anything, and you have refused to do that.  You are not "sticking with it," you are only spinning your wheels.  You are not making any progress because you do not know the fundamentals.  You do not know how to replace things in a query to adapt it to your situation because you never bothered to learn the structure of queries or the importance of data types, which are fundamental to any programming language, including PHP and SQL.

And I have told you this dozens of times and you still never stop and go back to the beginning and start where you should, you keep trying to make progress and you never do because you do not understand what you are working with.

The thing you are right about is that there is a repeating pattern.  So, what do you want to do, you want to continue repeating?  Or do you want to stop and try something else that actually works?

Share this post


Link to post
Share on other sites

For the moment, i am just going to keep going on with this with the example files.

I think I'll need to start from the beginning for php 7.  But I will have a difficult time with this, I don't think just going to start I will somehow get the hang of this, of where exactly would you be suggesting?

I want a change password feature and display only the logged in user's posted message forum.php will be a profile index. Of course that will need to be changed to remove only a logged in user's permission to view it, as it would need to be a public page forum.php?=1 or what ever it will look like.

 

Edited by Html

Share this post


Link to post
Share on other sites

And that example of the delete user, that is only for a specific name. How would I know exactly how to remove a user that is id 4, or 5? Based on that example?

On 9/24/2019 at 11:05 PM, Html said:

DELETE FROM Customers WHERE user_id='3';

Get id, I tried this before for the image upload, the first example. The second example looks like it could work since I have user_id and not id

# Get passed product id and assign it to a variable.
if ( isset( $_GET['id'] ) ) $id = $_GET['id'] ; 



# Get passed product id and assign it to a variable.
if ( isset( $_GET['user_id'] ) ) $user_id = $_GET['user_id'] ; 
Edited by Html
code example

Share this post


Link to post
Share on other sites

There are three different things that you need to be aware of: The name of the GET key, the name of the PHP variable and the name of the database field. When it comes to SQL, the only one that matters is the name of the database field. The code that you just provided only handles the GET key and the PHP variable.

You should start learning from the very beginning, the W3Schools PHP tutorial is a good place to start, but you have to read and understand every single page of the tutorial.

Share this post


Link to post
Share on other sites

For the moment, i am just going to keep going on with this with the example files.

OK.  So, you want to continue the repetition then.  That's up to you.

I think I'll need to start from the beginning for php 7.

And you think, what, the fundamentals between versions 5 and 7 are any different, or are different enough so that 7 is more complex or confusing?  Maybe you'll be surprised to learn that that vast majority of the fundamentals are identical, I don't know, that if you learn the fundamentals for any version then any later version is going to be much easier to learn.  That's up to you though if you want to continue to wait before learning the very basics of what you're attempting to use.

of where exactly would you be suggesting?

Well, since you seem to be pretty sensitive to various books either not saying enough or saying too much, maybe start with the free online tutorials and read through enough to them to get an idea about what you're working with.  My major suggestion would continue to be books.

The second example looks like it could work since I have user_id and not id

Why do you think the variable name has absolutely any relevance whatsoever?  If I want to design a database table to hold users and I decide to name the table "Cholula", and I want a column to hold each users' ID, and I decide to name that column "watermelon", and when I'm passing that user ID in a URL I decide to name the $_GET variable "cauliflower", do you think that the database, or the web server, or PHP, or any other Earthly thing really cares about my choice of names and is going to raise an error if I try to do this:

$stmt = $pdo->prepare('DELETE FROM Cholula WHERE watermelon = ?');
$stmt->execute([$_GET['cauliflower']]);

Maybe you do think it matters, I don't know, because you never read the part of the fundamentals that says that variable names don't matter and are arbitrary.  Maybe that's why you have such a hard time finding things that you think will work for you, because you have no clue that the actual identifiers and other names are 100% irrelevant to what the code does.  I don't know, but I guess you want to continue to repeat the pattern, so good luck.

Share this post


Link to post
Share on other sites

A $_session is going to be needed to know a particular id in the database row.

How does that work with a function code?

I had tried example code via a php site weeks ago which worked to solve my problem. I should of tried that.

session_start() ;

if ( !isset( $_SESSION[ 'user_id' ] ) ) { require ( 'login_tools.php' ) ; load() ; }

 

# Access session.
    session_start();
    $_SESSION[ 'user_id' ] = $data[ 'user_id' ] ;

 

A few snippets of code taken from the two files of the example files. I am guessing the example I tinkered with doesn't have a system to remember who is logged or belongs to a user id.

These sentences below are from the sessions tutorial on the site.

Quote

 

A session is a way to store information (in variables) to be used across multiple pages.

Unlike a cookie, the information is not stored on the users computer.

 

Quote

How does it work? How does it know it's me?

Most sessions set a user-key on the user's computer that looks something like this: 765487cf34ert8dede5a562e4f3a7e12. Then, when a session is opened on another page, it scans the computer for a user-key. If there is a match, it accesses that session, if not, it starts a new session.

 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...