InMotion Hosting Support Center

In our previous articles, we've created a simple website that allows for users to submit comments about an article. In this article we are going to walk through what happens when someone submits a comment in our test website.

Step 1 - Look at the data currently in the database

Before we post any comments to our database, we'll want to look at our comments table to see what is in it. To do this:

  1. Log into your cPanel and click the phpMyAdmin icon
  2. Click your database in the left sidebar, and then click on your table. If you're following our example, we'll first click on "_mysite" and then "comments".
  3. On the right side of the page, you'll see all of the comments submitted. If you refer to our screenshot below, you'll see we currently only have one comment, which is our test comment from a previous article:
    comments-table-in-phpmyadmin-with-one-test-record

Step 2 - Submit a comment on your website

At this point, we will replicate what a user will do, and that is leave a comment. To do this:

  1. Visit your first page, http://phpandmysql.inmotiontesting.com/page1.php?id=1. It is very important that "id=1" is in the URL, otherwise our php code will not know which article the comment belongs to.
  2. Input a comment and click submit (refer to screenshot below):
    inserting-our-first-comment-on-a-page

The comment has been Posted to the server and we now see a confirmation, "Thank you for your Comment!":
after-we-have-submitted-our-first-comment

At this point, we'll want to run the test again, but this time on page2. Click the link on the page to go to page2.php and insert another comment.

Step 3 - Confirm that your data has been written to the database

Now that we've submitted 2 test comments, we should be able to see them in the database. Follow the same steps from "Step 1" above to view the new comments in the database:
looking-at-phpmyadmin-after-2-test-comments

Now that we have comments in our database, we'll show you in our next article how you can access the database and display those comments on each page.

Continued Education in Course 205: Using PHP to create dynamic pages
You are viewing Section 6: Reviewing sample PHP code that interacts with a MySQL Database
Section 5: Using PHP to INSERT data into a database
Section 7: How to use PHP to connect to and retrieve data from MySQL

Support Center Login

Social Media Login

   
Social Login Joomla

Related Questions

Here are a few questions related to this article that our customers have asked:
Ooops! It looks like there are no questions about this page.
Would you like to ask a question about this page? If so, click the button below!
Ask a Question
n/a Points
2014-06-25 5:21 am

useful

n/a Points
2014-08-21 2:06 am

i tried and follow full example but the problem which i face is that my include statmnt not working all e.g  <? include("manage_comments.php"); ?>

as well the code for formcode and so on where include function used .. 

is it any alternative for all include stamnts which all used in this example.

Staff
25,902 Points
2014-08-21 7:47 am
Hello Yasir,

Include statements only serve to add the php that is in those files to the current file. You can certainly forgo any include statement and code the php there in the file. Includes are best used to separate code or to reuse the code in other files.

What type of error are you getting when you run the program regarding the include file? Some other formats for using include are:

<? include('manage_comments.php'); ?>
<? include 'manage_comments.php' ; ?>


In the examples above the file should exist in the same folder as the file that has the include statement.

Kindest Regards,
Scott M
n/a Points
2014-10-24 12:01 pm

I did exactly as stated in this tutorial. I submitted a comment from website and i gave a message as you mentioned "Thank you very much..."

But it didnt get updated in table. Any clue what could be the problem?Thanks

 

Staff
25,902 Points
2014-10-24 12:13 pm
Hello John,

You will want to start looking through the code. I would start where the code attempts to update the database. Does it give an error message when the update attempts to run? If so, what is the message? You may need to alter the code a bit to display this information. For example, change the code:
mysql_query($query);


To something like:
$return = mysql_query($query);


And then have it print out the variable to the screen:
echo $return;


This is a debug method so you will not want to leave it in the code after you check.

Kindest Regards,
Scott M
n/a Points
2015-01-29 10:43 am

I followed the tutorial from the beginning . I built the 4 pages in dreamweaver under one of my domains , was that a mistake ? I have not uploaded the 4 pgs yet , what should I do ?  I built the DB as instructed and copied the following as instructed , but have done anything with this yet , the instruction were to save it for use later  INSERT INTO `flamer5_TendersDB`.`tenders` (`id`, `email`, `website`, `opinion`, `timestamp`, `articleid`) VALUES ('john smith ', 'johns@domain.com', 'johnsmith.com', 'this is a test comment. ', CURRENT_TIMESTAMP, '');

Staff
15,445 Points
2015-01-29 1:52 pm
Hello Bill,

Thank you for contacting us. This guide is Section 6 of a tutorial series.

I recommend following the full series on Using PHP to create dynamic pages, since this is one of the last steps.

This will help you setup the initial pages, and database correctly.

If you have any further questions, feel free to post them below.

Thank you,
John-Paul
n/a Points
2015-04-17 9:36 am

I have no idea what i'm doing wrong I followed every step. and stll getting the page no longer exist. 

Staff
25,902 Points
2015-04-17 10:00 am
Hello,

I would like to take a look at your specific issue. Do you have a link you can provide that will display the error?

Kindest Regards,
Scott M
n/a Points
2015-04-17 10:11 am

when i put in the url in my browser that is the error message that I receive. And I did every step down to a T. 

http://phpandmysql.inmotiontesting.com/page1.php?id=1

Staff
25,902 Points
2015-04-17 10:37 am
Hello Franklin,

If that is the exact link you are using, you will need to replace 'phpandmysql.inmotiontesting.com' with your own domain name so it can find the right file.

Kindest Regards,
Scott M
2015-04-24 2:05 pm
how do i add the id=1 in my url. i am confused. i tried saving my file with page1.php?id=1, but it wont save. how do i then add the id in my url
Staff
23,894 Points
2015-04-24 5:07 pm
Hello Mosaik,

We're not quite sure what you mean by your question. You would not need to save that portion of the URL, unless you're adding it to a re-direct in the .htaccess file.

Regards,
Arnel c.

Post a Comment

Name:
Email Address:
Phone Number:
Comment:
Submit

Please note: Your name and comment will be displayed, but we will not show your email address.

13 Questions & Comments

Post a comment

Back to first comment | top

Need more Help?

Search

Ask the Community!

Get help with your questions from our community of like-minded hosting users and InMotion Hosting Staff.

Current Customers

Chat: Click to Chat Now E-mail: support@InMotionHosting.com
Call: 888-321-HOST (4678) Ticket: Submit a Support Ticket

Not a Customer?

Get web hosting from a company that is here to help. Sign up today!