Jump to content
Html

Php.ini file?

Recommended Posts

Erm, the login system I am using doesn't have that sort of setup. I only realised that, it is a first name, and surname only registration, so the account would have a page, but no actual name change feature.

But the problem here isn't that, it is getting the comments to the db to load on an index page.

The comment bit is a priority, otherwise there isn't anything to work with. I don't know what to do, if the tutorial info hasn't worked, I'm a bit lost here with this.

Share this post


Link to post
Share on other sites

But the problem here isn't that, it is getting the comments to the db to load on an index page.

Well, it sounds like the database is the problem then.  You need a unique ID to refer to each user.  You agree with that, right?  It wouldn't make sense if you had no way to identify a specific user.  If you're following a tutorial and they're telling you to set up a database so that users, or any database object, do not have a unique identifier, that is a major design flaw and I would probably find a different tutorial.  Any database table which holds information about what's called an entity or an object needs a unique identifier, and 9 times out of 10 the best way to do that is with an autonumber integer.  The only tables that don't need unique IDs for each record are tables which hold a relationship instead of an entity (e.g., a table which lists which groups a user is in - the users table and the groups table each need unique ID fields, but the table that just holds the relationship saying that a user is in a group doesn't need its own unique ID).

So, that's step number one, and you need to fix that problem before you move on with the comments.  You need to store the user's unique ID in that comments table so you can tell which comments belong to which users, so if you don't have a unique ID for the users then that's a problem.

Maybe I'm making some assumptions which aren't correct here.  I'm assuming this is a multi-user system where users can register, log in, and then leave comments for each other, where each comment was posted by a certain user for a certain user.  If that's not what you're trying to do then maybe I'm mistaken.  If you're trying to build a system where it's just a public comment page where anyone can write a comment without registering and they all show up on this page, first off there are a lot of security issues you need to be aware of with that, but in terms of the database you don't need a users table at all, just a comments table with a field for whatever you have in your form.  In order to list those comments on a page, that's just a normal select query on the database to get all of them.  If you haven't used a database at all, you should look at some of the database tutorials on w3schools first, there's no reason trying to learn how to walk before you've learned how to crawl.

Share this post


Link to post
Share on other sites

I don't know if that tutorial includes anything about user accounts and id for comments linked with them. The tutorial I think is about logging into a site,  comment on a video linked from youtube.

But the fact that you have stated this a bit more clearly for me to get, means that I may have to refer to another clip for this sort of task. That tutorial was the next best thing available. As the login system was just that, the user of that video tutorial hadn't gone further with it sadly, perhaps if he had, I may never of posted for this task here.

As for tutorials, youtube is really my chance for learning. One reason I never got moving with web design was the web page tutorials. But after so many years,  find it difficult to focus on this. But if I want to try and get something going, which I sort of have..with the help of a tutorial, and somebody's source files, just sort of cater it to my need, and sort of learn along the way.

 

 

Share this post


Link to post
Share on other sites

OK, but just be cautious about how you spend your time with this.  Books are typically far more useful than tutorials because you teach you the theory - the how and why.  In order to make something that works you need to understand why it works, not just how it works.  The problem with a lot of tutorials out there is that they don't teach you the why, they just tell you to type this or type that.  The guy in that tutorial might tell you to do a certain thing, but he might not explain why you do that, what it does, what your other options are, why he chose that option, etc, so you don't end up learning very much.  It would be a shame if you spent so much time trying to do this but end up not learning anything.  This is why books and lectures about the theory of what you're trying to do will end up teaching you a lot more than someone essentially just giving you a list of things to do.

As for tutorials, youtube is really my chance for learning.

Do you feel like you're learning, do you feel like you understand how this stuff works, and why it works?  Or are you just doing what someone tells you to do?  The fact that you put a PHP function name for your form's action tells me that you don't understand how this works.

One reason I never got moving with web design was the web page tutorials.

That's understandable, they are shallow and don't go into a lot of detail, just like video tutorials.  If you don't want to sit through classes and lectures then reading books about this stuff will probably give you the greatest amount of knowledge in the shortest amount of time.  You need to learn the fundamentals though, things like how to process forms, how to interact with a database, etc.  If you knew how to process forms, how to use a database, and how to use the session then you would know all you need to build any kind of login system, comment form, etc.  All of those things use the same set of fundamental tools.  That's what you need to learn, not a lesson on what to type to display a form and put it in a database where you wouldn't be able to take that and use it in another situation not specifically covered by that tutorial.

I'm not trying to be critical or harsh, don't take anything personally.  I'm just trying to be efficient with time.

You can probably find several lists of best PHP books, like this one:

https://www.cloudways.com/blog/best-books-to-help-you-learn-php/

Just a word of caution there - check the publication date.  The last one on that list, for example, Programming PHP, was great when I got the first edition in the late 90s or whenever that was.  Today, the first edition of that book would be completely useless.  They list the third edition on that page, but when checking for PHP books I would skip over anything not published within the last 2 or 3 years.  I like O'Reilly as a publisher though, they have a lot of good stuff.

Share this post


Link to post
Share on other sites

Hey there Justsomeguy,

Interesting outlook you've stated there, I did buy one book which I had hoped would help with this, early in the year. I think I did mention it in another thread. Php 7 in easy steps by Mike McGrath, I got that on Amazon UK for under £10. It appears the only useful tutorial in it was a contact form.

As for the youtube, well I prefer the more narrated stuff, reading from a book just isn't the same for me. As for knowing the theory, not really, no. I had banked on learning some of that in a video tutorial, all I can really do is just try them out. But I've stumbled here, as trying to get something from one clip tucked into another has stopped so far from getting the result I wanted. I'm going to see what else I can find.

Thanks for the book suggestions. I think the video narration is more suitable for me.

 

In the Chapter Making a connection, it explains about making a forum. I may of overlooked that part.

Now this person uses connect_db.php

Creating a forum,

Then goes on to state a database table , post_id, first_name, creating a table in the SQL box in the db area, done that in the first tutorial.

Processing messages,

If( isset($_POST['message']))

{

If(!empty(trim($_POST['message'])))

{$first_name = addslashest($_POST['first_name']);}

else { fail('First Name');}

}

('../connect_db.php');

$sql = "INSERT INTO forum

(first_name,) and etc

Values('$first_name'. etc

add failure code, etc, then save as process.php

Confirming Success,

Then on the next page that section, shows a display of text.

 

Hmm. I could take a snapshots of these pages. Of course this doesn't use an existing name, it requires to type one in a form, and then it is processed to save in a db.

Edited by Html
Read a chapter in the book

Share this post


Link to post
Share on other sites

That's the kind of thing you need to learn.  Forget about tutorials.  You don't need to learn how to do specifically what you're trying to do, or a tutorial to show you how to do exactly the thing you're trying to make.  Learn how to get form data in general, and validate it.  Learn how to insert into a database in general, and select that data.  That's all a comment page is.  A form to post a comment, and a page to list them.  Inserting into a database, and selecting from the database.  Don't waste time trying to find a single tutorial that does everything you're trying to do, just learn the basic pieces and you can use them to build something as big as you can design.

Share this post


Link to post
Share on other sites

For what it's worth, and not that my experience is the same as yours, but when I read through my first PHP book I didn't do any of the tutorials or examples at all.  I was focused only on the theory and how to do the small individual tasks, like getting form data or manipulating an image.  Once I had an idea about how to do those things then I designed a small project that would use everything that I wanted to learn (file uploads, login sessions, editing images, databases, managing files on disk, etc; my project was a photo gallery).  Then I built it piece by piece, and for each small piece I would look up the online documentation and things for the specifics about what I needed to use, like the list of string or array functions on php.net.  It's not about memorizing everything or being able to follow a list of specific steps to end up with the same code as in the book, it's about understanding in general how things work and then being able to look up the specifics you need to accomplish the task.

Share this post


Link to post
Share on other sites

Yes, I just wanted it the way I preferred it. I really don't know what I'm going to do, I'm stuck at this moment, I can perhaps give that tutorial in the book a go, but from there on, I don't know. Thank you for the advice.

I did try and look for some other tutorials certain keywords on the video site, yes nothing.

I also tried this with Java programming for Android, haven't gotten far with that either, made a program, doesn't install on an old mobile device. How ever, there are plenty of video tutorials with some quality sadly compared to the PHP stuff.

 

Edited by Html

Share this post


Link to post
Share on other sites

Then basically everything you want is here

https://www.w3schools.com/php/default.asp

Under PHP forms.

Just strip out unwanted inputs, adjust required retrieved $_POST[], validation, etc

So when all these values are retrieved for insertion into database, move on to

 https://www.w3schools.com/php/php_mysql_prepared_statements.asp

Once these values are inserted, you can move on to showing these inserted data by using

https://www.w3schools.com/php/php_mysql_select.asp

All you have to do is create database (many) with table for the comments with

comment_id: type int (auto_increment), user_name: type 'char', comment_content: type 'text', date: type 'timestamp'

All you really need to supply is user name, and comment for insertion, the id is not required for insertion as it auto_increment with every new record for you, the date, can be taken care of by using MYSQL 'NOW()' within the SQL select statement, which will store the date/time it was inserted.

If you then want to add separate table (one) for user id, name etc and link the two (one to many), you can do that later, when your more confident.

Share this post


Link to post
Share on other sites

As I stated in previous posts, I need more the narration to understand what to do.

Okay if I leave aside this sent a comment task to the db, and display it on a profile page. Once I register an account, how do I create a profile page? Like an index, with a textbox there, obviously the textbox is sort of straightforward since that is the html, and I have done that previously.

Share this post


Link to post
Share on other sites

Create a file which takes the account ID in the URL, and uses that to look up the account in the database and display whatever you want for the account on that page.  The URL would be something like profile.php?id=10, and you check $_GET['id'] for the ID in the URL, validate it, look up the account with that ID, and display whatever you want on the page.  You can show the account details, etc.  If you have a form for submitting a comment there, you need to pass the account ID through to that form also so it knows which account to add the comment for.  You can do that with a hidden input, for example:

<input type="hidden" name="account" value="<?php echo $id; ?>">

Share this post


Link to post
Share on other sites

Erm, right so id 1 which is in the db as a name, and surname, how does that get into a file. The primary profile.php is the same for any name registered.

So a profile.php?id-1 this would be a new empty page linked from profile.php.

Share this post


Link to post
Share on other sites

That is a GET querystring (should be profile.php?id=1 ), placed at the end of file, it will go to that specific file, with the use of $_GET['id']  with 'id' being a index key will have value of 1 attached to it

$id="";

$user_id="";

if ($_SERVER["REQUEST_METHOD"] == "GET") {
if (isset($_GET["id"])) {
$user_id=$_GET["id"];
}

///process profile to id retrieved


}

If this is sent from the same file 'profile.php' from form input. it original would not get pass

if ($_SERVER["REQUEST_METHOD"] == "GET") 

because no GET querystring (?id=1) existed. Only after the form is submitted to itself, and retrieves the id, can the processing of profile can commence to get all data retaining to this specific id reference.

Share this post


Link to post
Share on other sites

Just to clear, there's only 1 file called profile.php, no other profile files, and that one file gets the ID and displays that profile.  You don't create a new file for each profile, you have 1 page for viewing any profile.

Share this post


Link to post
Share on other sites
<?php
/* Displays user information and some useful messages */
session_start();

// Check if user is logged in using the session variable
if ( $_SESSION['logged_in'] != 1 ) {
  $_SESSION['message'] = "You must log in before viewing your profile page!";
  header("location: error.php");    
}
else {
    // Makes it easier to read
    $first_name = $_SESSION['first_name'];
    $last_name = $_SESSION['last_name'];
    $email = $_SESSION['email'];
    $active = $_SESSION['active'];
}

$user_id="";

if ($_SERVER["REQUEST_METHOD"] == "GET") {
if (isset($_GET["id"])) {
$user_id=$_GET["id"];
}

///process profile to id retrieved


}
?>

So like that?

Share this post


Link to post
Share on other sites

Well, if this is a page only for people to view their own profile, then you don't need to pass the ID through the querystring, you can just get their info from the session.  You would pass the ID in the URL if people can look at other profiles, and then you need to tell the page which profile to show.

Although it's not really useful to check if the request method is get, the vast majority of requests are get requests.  A get request is any time you just type a URL, or click a link, or get redirected.  A post request is when you submit a form.  If you're only showing the profile when it's a get request, then if you had a comment form on that page, submitting the form would cause the profile to not be displayed.

Share this post


Link to post
Share on other sites

Once registered, the next page profile.php with a link to confirm, I removed that, and added in a textbox, as I've display in the previous code postings. I would need to add a profile link to then display that user's profile page so 1. So, that below would be the hyperlink.

profile.php?id=1

Share this post


Link to post
Share on other sites

Right, you put the account ID in the URL for the profile you want to display.  Incidentally, this is another reason why your database needs unique IDs for everything.

Share this post


Link to post
Share on other sites

Right, but if I add a link onto  that page, the page won't load with the 1, how would it know? The bit at the bottom is the part that would work that out.

 

<?php
/* Displays user information and some useful messages */
session_start();

// Check if user is logged in using the session variable
if ( $_SESSION['logged_in'] != 1 ) {
  $_SESSION['message'] = "You must log in before viewing your profile page!";
  header("location: error.php");    
}
else {
    // Makes it easier to read
    $first_name = $_SESSION['first_name'];
    $last_name = $_SESSION['last_name'];
    $email = $_SESSION['email'];
    $active = $_SESSION['active'];
}

$user_id="";

if ($_SERVER["REQUEST_METHOD"] == "GET") {
if (isset($_GET["id"])) {
$user_id=$_GET["id"];
}

///process profile to id retrieved


}

date_default_timezone_set('Europe/London');
include 'comments.php.inc';
include 'connect.inc.php';
?>
<!DOCTYPE html>
<html >
<head>
  <meta charset="UTF-8">
  <title>Welcome <?= $first_name.' '.$last_name ?></title>
  <?php include 'css/css.html'; ?>
</head>

<body>
  <div class="form">

          <h1>Welcome</h1>
          <a href="profile.php?id-1"><button class="button button-block" name="View profile"/>View profile</button></a>
          <p>
          <?php 
     
          // Display message about account verification link only once
          if ( isset($_SESSION['message']) )
          {
              echo $_SESSION['message'];
              
              // Don't annoy the user with more messages upon page refresh
              unset( $_SESSION['message'] );
          }
          
          ?>
          </p>
          
          <?php
          
          // Keep reminding the user this account is not active, until they activate
          if ( !$active ){
              echo
              '<div class="info">
              Account Created!
              </div>';
          }
          
          ?>
          <?php echo
           "<form method='POST' Action='".setComments."'>
           <input type='hidden' name='uid' value=''>
           <input type='hidden' name='date' value='".date('Y-m-d H:M:S')."'>
           <textarea name='message'></textarea>
           <button type='submit' name='commentSubmit'>Comment</button>
           </form>";
             ?>
          <h2><?php echo $first_name.' '.$last_name; ?></h2>
          <p><?= $email ?></p>
          
          <a href="logout.php"><button class="button button-block" name="logout"/>Log Out</button></a>

    </div>

</body>
</html>

Just below the welcome tag, I duplicated the button used for logout, and renamed it, and added a the link. Of course this doesn't go anywhere..

Edited by Html
Added the page code.

Share this post


Link to post
Share on other sites

I'm not sure what you're asking.  If you have a PDO object connected to your database, and you wanted to print a list of accounts with a link to their profile, you might do that like this:

$stmt = $pdo->prepare('SELECT id, username FROM users ORDER BY username ASC');
$stmt->execute();
$accounts = $stmt->fetchAll();

foreach ($accounts as $account) {
  echo '<a href="profile.php?id=' . $account['id'] . '">' . $account['username'] . '</a><br>';
}

That code would go wherever you want to list the accounts, not necessarily on the profile page itself (but you can really put whatever you want on whatever page though, you're the designer).  On that profile.php page you would get $_GET['id'], and look it up:

$stmt = $pdo->prepare('SELECT * FROM users WHERE id = ?');
$stmt->execute([$_GET['id']]);
$account = $stmt->fetch();

echo 'Showing profile for ' . $account['username'];

There would be some additional error checking and other things you would want in that code, but that's the general idea.  You can see on this page, for example, that each of our usernames is a link to our profile page.  It's the same idea.

Share this post


Link to post
Share on other sites

When the user logs in with username and password it is compared to those stored in database, then the user id is retrieved and that is used in each page to retrieve the data required for those pages, using sql select statement where userid matches id retrived on login.

 

Share this post


Link to post
Share on other sites

:blink:

Okay from the top, so the code I put into the profile has that link, as well as the get code that dsonesuk mentioned in the previous post.

I left that out, so there is no link in that part there.

$user_id="";

 

<body>
  <div class="form">

          <h1>Welcome</h1>
          <a href="profile.php?id-1"><button class="button button-block" name="View profile"/>View profile</button></a>
          <p>

Share this post


Link to post
Share on other sites

Once you have successfully login, id is retrieved the value is applied to $user_id, whenever id is used for GET querystring it will be used in you example as

	<a href="profile.php?id=<?php echo $user_id; ?>"><button class="button button-block" name="View profile"/>View profile</button></a>
	

So any authenticated logon where id is retrieved, will use that id passed through anchor querystring, form submitted GET querystring or POST value to retrieve that specific users details.

 

Edited by dsonesuk

Share this post


Link to post
Share on other sites

Right, and what does that new link do? It only loads as profile.php?=

As for Justsomeguy's post, that code fits into the profile php file

$stmt = $pdo->prepare('SELECT id, username FROM users ORDER BY username ASC');
$stmt->execute();
$accounts = $stmt->fetchAll();

foreach ($accounts as $account) {
  echo '<a href="profile.php?id=' . $account['id'] . '">' . $account['username'] . '</a><br>';
}

Share this post


Link to post
Share on other sites

That code is not specific, it will show all users with a link to the profile page that have value representing the users id reference from database.

<a href="profile.php?id=1">Tom</a>
<a href="profile.php?id=2">Dave</a>
<a href="profile.php?id=3">Harry</a>

Options:

1)login to specific user details:

When a user logs in it should retrieve that users id from database, that id is used to show that specific users details,

2) list all users as above Tom, Dave .. example:

A link is clicked and goes to profile.php with user id.

For both (1) and (2)

That id is sent to profile.php as part of the querystring, on entering the profile.php page that id value is retrieved from querystring and assigned to a variable, that variable is used in the SELECT statement to retrieve details that a record holds that matches the exact same id that id variable equals. Then you loop each column of that id row , gathering that columns details (text content, image path etc), and filling pre-defined html in the profile.php page to accept those details.The predefined html will be the same for all, the details from database for that specific user will be different only

Edited by dsonesuk

Share this post


Link to post
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

×