One of my tutorial followers graciously emailed me with an interesting problem, when they tried to use my blog tutorial(#13), when they put in asian characters, they went into the database wrong. AND if directly put into the database, it would echo out as ????
This can be a very annoying problem, one that I found the solution to.
So, in my example in connect.php(where the database connection is established) after the line that has the mysql_selectdb in it the following has to go after that, but before the ?>
mysql_query(“SET character_set_results=utf8″);
mysql_query(“SET character_set_client=utf8″);
mysql_query(“SET character_set_connection=utf8″);
mb_language(‘uni’);
mb_internal_encoding(‘UTF-8′);
Next, the forms that submit data have to be modified to accommodate the character set(for some reason PHP or the browser gets it wrong and it turns into a mess.
If you set the attribute in the <form> tag
accept-charset=”UTF-8″
It should send to the server correctly.
SO… like <form accept-charset=”UTF-8″ action=”blah.php” method=”post”>…..</form>
Also, to make sure it displays correctly on the page, wrap it with iconv( ‘UTF-8′, ‘UTF-8′,$row['title']); or mb_convert_encoding($row['title'], ‘UTF-8′ );
However, I noticed it doesn’t like htmlentities wrapped around it or anything like utf8_encode, or what ever. So be sure to test!
This tutorial in essence goes over implementing posting and inserting data into a database, along with data validation for the blog. This one also extends on Tutorial 10, 11, 12, so please check those out if you have not.
Here’s the plan:
Make a page for posting
Make a form
Get the SQL for inserting
Prepare and validate data
Test page functionality
Finalize and clean up
Part 1:
Make sure to click on Read More so that you may see Part 2 and the sources. Read more…
This tutorial goes over the concept of uploading files, and keeping records in a MySQL database.
So lets try this
When: I need to upload files and keep long term records on who uploaded and where it is.
Why: I don’t know, you make up the reasons.
What: Exactly do you need to keep record of? Time, who sent it, where is it?
Who: Depends on how you implement
Where: On the Internet!
How: I’ll show you.
There are two parts, so pay attention closely. (The last part is always the most important) Don’t forget to see more of this post for the sources and part two!
This tutorial goes over the concept of a log in system with MySQL with sessions. (The sources are provided after the jump)
One of my viewers sent me a message on youtube requesting this great example
Dear kloplop321,
I really want to make a php, mysql based game. I have an idea about how I am going to do it. I would just really love some help with the SESSION login. There are tutorials on the internet but I find that they don’t show the full code or stuff like that. So if you would please create a tutorial on it I would apprecitate it. Thanks.
This tutorial naturally has the sources provided.
The following videos(2) go over the concept of a login system in PHP while using sessions(to maintain the login status) and MySQL(a database that holds the information). I first go over how to make
the login page
the table in the database
a user through PHPMyAdmin[the next tutorial will likely go over registering users]
code how to validate that user and if they are validated
if so, set the session information
if acceptable, they can go to a “members only” page [which only allows identified people in]
a way to log out
Again: this tutorial is pretty much a walk-through in concept of a mysql login system.
Part 2 (the most important) and the sources after the jump. Read more…
This is pretty much a basic “How to” for making a very basic guestbook that uses a database instead of text. I go over everything from making the database to the table, the html form and actual posting. If you watch this video you will pretty much see the basic idea of what a guestbook is, how they work, and how to make a basic one yourself.
This video has two parts, so to understand fully, please watch both.
I’ve decided to record how to make complete solutions for a certain problem from a High School programming competition, and the solution for it.
The problem: You are to write a program which will input a positive integer n and output the number of
divisors of n and the sum of those divisors. (Note: by divisor we mean a positive integer
divisor this includes 1 and n.)
Developers often use the handy features included with databases to create solutions in PHP for what ever needs to be satisfied. Databases have functions like quickly matching data to Identifications, searching large sums of data, holding user information and much more that developers can utilize. There are many ways to use a database, or in this case, to interface with a database. Most databases use a rough standard of a Structured Querying Language, which is like code that the SQL server or application interprets. Read more…
Want to dump your database? This video goes over the export feature of PHPMyAdmin which allows you to create and save file dumps of your database. You can use these dumps to make a duplicate database or update a pre-existing database. Or simply to backup regularly in case of database failure. I also marginally go over importing and how to import.
I hope everyone has a great new years day in 2010!
And on the side note, the editor I use is called Komodo Edit. It is Free! http://www.activestate.com/komodo_edit/