Welcome to Egypt Forums Mark forums read | Egypt Main Page
Egypt Forums
Arabic Movies



Articles Thread, Creating a Simple Comments and Login System using MySQL and PHP in MySQL / PostGRESQL; Creating a Simple Comments and Login System using MySQL and PHP Now that we’ve got a simple understanding of how ...

Short Link: http://forum.egypt.com/enforum/showthread.php?t=6705


Reply
LinkBack Thread Tools Display Modes
Creating a Simple Comments and Login System using MySQL and PHP
 
 
The God Father
Developer's Avatar

Reply With Quote
Thanks: 1
Thanked 212 Times in 154 Posts
 
Join Date: Jul 2008
Location: NDC
Posts: 5,426
26-11-2008, 07:52 PM
 
Creating a Simple Comments and Login System using MySQL and PHP

Now that we’ve got a simple understanding of how to perform SELECT, INSERT and UPDATE MySQL queries (and if not, have a quick review from the last couple of tutorials) we can now work on building ourselves a very simple PHP application to accept user data and save it into our database. This information will then be displayed to anyone visiting the site. We’ll also take a quick look at how we can generate a script to authenticate administrative users based on a username and password combination and allow those admin users to delete unwanted comments from the database.
A simple comment system using PHP and MySQL



The first thing we’ll need to do is generate the HTML form that we’ll use to accept the user data, and include a couple of important settings which will let us access this information later, once the user has submitted the form.
First, here’s the code you’ll need to use to generate the HTML form. Save this file somewhere in your PHP directory, with the name mysql_form.php
PHP Code:
A simple PHP/MySQL form
<h2>Please enter your name and a comment</h2>
<
form action="form_submit.php" method="post">
Name :
<
input size="32" type="text" name="username" /><br>
Comment : <textarea cols="40" rows="5" name="comment"></textarea><br>
<
input type="submit" value="Send comment" />
</
form>
Here, we’re using the <form> tag to generate a set of text-entry boxes where a user can enter their details, to be sent to the server for processing. We have specified that we wish the data to be sent using the POST delivery method. This simply means that the data will be sent within the request to the server, rather than attached to the query string, as would be the case if we were using the GET method.
Next, we need to create another file which will receive the request from the user, and process the data accordingly. We have specified that this file will be called form_submit.php. Create this file, and within it add the following code
PHP Code:
<?php
include("db_connect.php");
$username = $_POST['username'];
$comment = $_POST['comment'];
if(
get_magic_quotes_gpc()){
  
$username = stripslashes($username);
  
$comment = stripslashes($comment);
}
$username = mysql_real_escape_string($username);
$comment = mysql_real_escape_string($comment);

$result = mysql_query("INSERT INTO comments (name, comment) VALUES ('$username', '$comment')");
if(
$result == true) {
  echo
"The comment was added successfully";
} else {
  echo
"The comment could not be added, there was an error";
}
?>
<br/><a href="mysql_form.php">Go back to the comments page</a>


Before we go any further here, I’ll need to give you two things. Firstly, the contents of the file db_connect.php. What I’ve done here is simply place the mysql_connect() function within the file db_connect.php to save us having to type out the database connection code twice, as we’ll be adding that into our initial HTML file, mysql_form.php, in just a moment. Here is the connection file as it is set up on my computer (you may need to change the values to suit your installation of PHP)
PHP Code:
<?php
$link
= mysql_connect('localhost', 'root', 'pass'); //Connects to the database at "localhost"
mysql_select_db  ('test', $link); //Assuming you have a database named "test" set up
?>


Secondly, you’ll need the structure for the “comments” table. This should be created in the same database as is defined in the connection file above
PHP Code:

  DROP TABLE
IF EXISTS `comments`;
CREATE TABLE IF NOT EXISTS `comments` (
  `
id` int(11) NOT NULL AUTO_INCREMENT,
  `
name` varchar(64) NOT NULL,
  `
comment` text NOT NULL,
  
PRIMARY KEY  (`id`)
)
ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
</div></div> Notice how I’ve defined three columns, the first being an “id” column thay is also declared as a PRIMARY KEY, as well as having the AUTO_INCREMENT attribute set. This is very common practice in MySQL tables, and means we don’t need to concern ourselves with having comments with duplicate names, for example. These unique IDs also give us an easy way to refer to specific comments by number when administrating them at a future date, or deleting comments we don’t wish to keep.
Test Run



Try out the code I’ve included above. You should be able to see an HTML form and, when you submit that form, you should see a page saying “The comment was added successfully”. If not, then something has gone wrong and you should go back and recheck your code.
Checking for invalid data



One thing you might notice is if you try and submit the form without adding a name or a comment, then the MySQL query will still complete without a problem, and you’ll be left with a blank entry in the database. One way to get around this is to modify our code to check for such a situation and, if no data has been entered, prompt the user to go back and try again. The following change to form_submit.php will add this behaviour
PHP Code:
<?php
include("db_connect.php");
$username = $_POST['username'];
$comment = $_POST['comment'];
if(
get_magic_quotes_gpc()){
  
$username = stripslashes($username);
  
$comment = stripslashes($comment);
}
$username = mysql_real_escape_string($username);
$comment = mysql_real_escape_string($comment);
if(
strlen($username) == 0 || strlen($comment) == 0){
  echo
"You didn't enter all the data. Please go back and retry";
} else {
  
$result = mysql_query("INSERT INTO comments (name, comment) VALUES ('$username', '$comment')");
  if(
$result == true) {
    echo
"The comment was added successfully";
  } else {
    echo
"The comment could not be added, there was an error";
  }
}
?>
<br/><a href="mysql_form.php">Go back to the comments page</a>


If you try again, you’ll now see that the form will not accept blank data.
There’s a great deal more to consider when accepting user input into your database, and we’re going to look at that in further detail in the next section. For now though, we’ll continue with our example, and provide our visitors with some feedback on the comments posted so far
Modifying the HTML file to display the user comments



With a little bit of modification, we can adjust the file we created earlier, mysql_form.php to display all the comments submitted so far
<span style="color: rgb(0, 0, 0); font-weight: bold;">
PHP Code:
<?php
include("db_connect.php");
$comments = mysql_query("SELECT * FROM comments ORDER BY id DESC LIMIT 0, 10");
?>
A simple PHP/MySQL form
<h2>Please enter your name and a comment</h2>
<form action="form_submit.php" method="post">
Name :
<input size="32" type="text" name="username" /><br>
Comment : <textarea cols="40" rows="5" name="comment"></textarea><br>
<input type="submit" value="Send comment" />
</form>
<h2>Here are the comments submitted so far</h2>

<?php
if($row = mysql_fetch_array($comments)){
  do {
    echo
"<h3>{$row['name']}</h3>";
    echo
"{$row['comment']}";
  } while (
$row = mysql_fetch_array($comments));
} else {
  echo
"There are no comments";
}

?>
In our extended example, we’re making use of the ORDER BY and LIMIT keywords to show only the 10 latest comments, in order from newest to oldest.
If you try out the code above, you should see the same form on the page mysql_form.php, and underneath, a list of all the comments you’ve added. If you try adding a new one, and then return to this page, you should see it appear at the top of the list.
On the next page, we’re going to expand on our example, and see how it’s possible to add in some administration priveleges to a select group of people using the power of PHP and MySQL

C Ya i will send more php lessons soon in php section
__________________
I Love Walking In The Rain Cuz Nobody Know I'm Crying !!
 
 
 
 
Junior Member

Reply With Quote
Thanks: 0
Thanked 0 Times in 0 Posts
 
Join Date: Mar 2009
Location: Tanzania
Posts: 17
12-03-2009, 01:48 AM
 
All Popular Softwares For PC and MACAll European LanguagesThe financial crisis? SAVE YOUR MONEY!Special code - D33W-3333 - and you will get a DISCOUNT of up to 30% for our all software !microsoft office 2003-------------------------------------------------------------------------------------Windows XP Professional With SP2 Full Version $59.95Adobe Creative Suite 4 Master Collection $329.95Office Enterprise 2007 $79.95Windows Vista Ultimate 32-bit $79.95Adobe Photoshop CS4 Extended $119.95Adobe Creative Suite 4 Master Collection for MAC $329.95Adobe Acrobat 9 Pro Extended $99.95Office 2003 Professional (including Publisher 2003) $59.95AutoCAD 2009 32 and 64 bit $169.95Microsoft Office 2008 Standart Edition for Mac $99.95Adobe Creative Suite 4 Design Premium $259.95Adobe Photoshop CS4 Extended for MAC $119.95-------------------------------------------------------------------------------------The financial crisis? SAVE YOUR MONEY!Special code - D33W-3333 - and you will get a DISCOUNT of up to 30% for our all software !windows xp software to buyNo torrents - no claim. Read our Testimonials.
__________________
pocket software
 
 
 
 
Member

Reply With Quote
Thanks: 0
Thanked 0 Times in 0 Posts
 
Join Date: Mar 2009
Location: Italy
Posts: 32
21-03-2009, 01:30 AM
 
All Popular Softwares For PC and MAC
English, Deutsch, French, Italy, Spanish Version

The financial crisis? SAVE YOUR MONEY!
Discount Code - D33W-3333 - and you will get a DISCOUNT of up to 30% for our all software !
Discount Code - ADBE-3333 - and you will get a DISCOUNT of up to 50% for our Adobe software !

used software

-------------------------------------------------------------------------------------
Windows XP Professional With SP2 Full Version $59.95
Adobe Creative Suite 4 Master Collection $329.95
Office Enterprise 2007 $79.95
Windows Vista Ultimate 32-bit $79.95
Adobe Photoshop CS4 Extended $119.95
Adobe Creative Suite 4 Master Collection for MAC $329.95
Adobe Acrobat 9 Pro Extended $99.95
Office 2003 Professional (including Publisher 2003) $59.95
AutoCAD 2009 32 and 64 bit $169.95
Microsoft Office 2008 Standart Edition for Mac $99.95
Adobe Creative Suite 4 Design Premium $259.95
Adobe Photoshop CS4 Extended for MAC $119.95
-------------------------------------------------------------------------------------

The financial crisis? SAVE YOUR MONEY!
Discount Code - D33W-3333 - and you will get a DISCOUNT of up to 30% for our all software !
Discount Code - ADBE-3333 - and you will get a DISCOUNT of up to 50% for our Adobe software !

pda software


No torrents - no claim. Read our Testimonials.
__________________
computer stores
 
 
 
 
Junior Member

Reply With Quote
Thanks: 0
Thanked 0 Times in 0 Posts
 
Join Date: Apr 2009
Location: Brazil
Posts: 2
02-04-2009, 07:39 PM
 
free lesbian sex strap videwo free porn movies window media , bush download interracial pordn brazilian sex clip clip fucking katin porn star ebony porn videos , black clip gay man muscle sex xxx . Also couple sex swapping video and audioclip sex deep throat blow job movie porn clip free sexy video woman amateur homemade sex videos bisexual sex movies videos de porno gratis man movie muscled sex best film sex scene turtle sex video clip lesbian lesbian sex . And free lesbian porn site video video de sexo free gallery mature movie sex . Also free sexy lesbian video clip .
 
 
 
 
Junior Member

Reply With Quote
Thanks: 0
Thanked 0 Times in 0 Posts
 
Join Date: Apr 2009
Location: Virgin Islands
Posts: 21
06-04-2009, 06:04 AM
 
Cheap Acomplia, Buy Cheap Valium Online Buy Ativan No Prescription, Discount Generic AtivanGeneric Celebrex Online, Discount Acomplia Celexa, Cheap Zithromax Online Buy Cheap Lipitor, Generic Zoloft Online Order Cheap Paxil, Buy Lipitor On Line Paxil Medication, Effexor Sales Buy Soma, Propecia Rogaine Buy Generic Viagra Online, Buy Generic Ambien Zyban Pills, Ativan 1mg Zyban No Prescription, Generic Ambien Zolpidem Ambien Pill, Cheap Generic Zoloft Cialis Pills, Discount Xenical Generic Prozac Fluoxetine, Order Celebrex Tramadol Prices, Cheap Generic Effexor Diazepam Online, Cheap Generic Buspar
 
 
 
Reply

Articles Thread, Creating a Simple Comments and Login System using MySQL and PHP in MySQL / PostGRESQL; Creating a Simple Comments and Login System using MySQL and PHP Now that we’ve got a simple understanding of how ...

Short Link: http://forum.egypt.com/enforum/showthread.php?t=6705


Bookmarks

Tags
comments, creating, login, mysql, php, simple, system


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Face Recognition Login v1.2.1 Developer Software and Programs 0 17-12-2008 06:37 PM
MySQL 5.0.51b Developer Software and Programs 0 22-10-2008 03:32 PM
Delete Xp & Vista Login Password Developer Software and Programs 0 09-10-2008 06:24 PM
MySQL 5.0.51b Developer Software and Programs 0 09-10-2008 05:53 PM
Add AdSense to login page Developer Mods for 3.6.x 0 29-09-2008 10:52 PM