954,595 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Database - CPanel

A friend referred me to this forum knowing I've been struggling for quite a while unable to find proper help. She says the people here are excellent and quick to respond. I do hope I am posting this is the correct forum area.:-/

My problem is is that I have a website hosted and my host allows me to use CPanel to create databases. However, I am unsure how the heck to implement these databases in my website in any sort of way. I hope that someone here knows how to use CPanel and could help me with this issue because my website would be much more fantastic if only I could use databases. Please help me out.:(

Spunky
Light Poster
34 posts since Jun 2009
Reputation Points: 10
Solved Threads: 0
 

what I had to do, after a long discussion with a tech suport that hardly speak engish that I have to add the username before the databse name..
example:

mysql_select_db("username_database"

hope this helps.

PS:
look some were else before calling costumer service.

elamigosam
Light Poster
31 posts since Jun 2009
Reputation Points: 10
Solved Threads: 2
 

I know how to create the database as well as I created a user with a password for it. I've even added data to the database. I just dont know how to incorporate it into my created website.

Spunky
Light Poster
34 posts since Jun 2009
Reputation Points: 10
Solved Threads: 0
 

Ok. Let me explain my issue a little better.

I've used CPanel to create databases, I give them a name, I apply a user to them, and in PHPMyAdmin I can create tables and add data to the tables. Now, what I need to know, is how to get my website to search these databases? How do I show this data on my website according to what link is selected, so its pulled from the database what is shown?

Spunky
Light Poster
34 posts since Jun 2009
Reputation Points: 10
Solved Threads: 0
 

You'll need a language to connect to them, for example PHP, Python, Ruby.

In PHP the code would look like this:

$db_link = @mysql_connect('localhost', 'youruser', 'yourpass') or die(mysql_error());
@mysql_select_db('yourdatabase') or die(mysql_error());
$query = 'SELECT * FROM yourtable';
$result = @mysql_query($query) or die(mysql_error());
if ($result)
{
  while ($row = mysql_fetch_assoc($result)) 
  {
    // use your data
  }
  mysql_free_result($result);
}
if ($db_link)
  mysql_close($db_link);
pritaeas
Posting Expert
Moderator
5,484 posts since Jul 2006
Reputation Points: 653
Solved Threads: 875
 

Yea, I knew to use PHP, guess I should have said that. But thank you. That's a start. I don't know PHP but the best way to learn is hands on. So, I'm guessing all that connects me to the server, but then, what do I put in the "// use your data" area? Like, could you point me in the right direction of where to learn what goes there? I use w3schools to learn the web languages including PHP. However, all I seem to find on there is code that creates the database as well as insert data in it. But CPanel already does that..?

Spunky
Light Poster
34 posts since Jun 2009
Reputation Points: 10
Solved Threads: 0
 

first of all you need a goal,
like me I have a site where you can add songs and lirics to it, so a user enter the site, selects its church and then sees a list of songs that his church plays, so the "//use your data" becomes title songs and authors name, and lirics.

if you have a goal already, tellus what is it that you want to do and that should help us determine what to show you.....

elamigosam
Light Poster
31 posts since Jun 2009
Reputation Points: 10
Solved Threads: 2
 

Alright then. My website is a World of Warcraft Fansite. It isn't official yet and probably wont be for a very long time. But I am ok with that, this is a learning experience.

To start out with getting a database going I'm starting with the Achievements page. In the game you can earn different achievements by accomplishing certain tasks. There are hundreds of achievements and they are listed into different categories. I.E Quests, General, Exploration, Professions. Things like that. I want it to be like where you click on a link, say, Quests, and then it lists all of the Quest achievements out that are stored in the database, and all the info that is stored with it, like how many achievement points it awards and the description of how to accomplish it. I want to be able to make it cool looking though ofcourse, not just list it in a table. But I have to start out with the basics. I'd be exstatic just to get my info to show on my page from my database.

Spunky
Light Poster
34 posts since Jun 2009
Reputation Points: 10
Solved Threads: 0
 

This will print just one column name:

while ($row = mysql_fetch_assoc($result)) 
{
    // use your data
    echo $row['column_name'] . '<br/>';
}


Play around with it first, and when you have new/more questions, post them.

In addition, it may be worthwhile to check out Smarty, to be able to separate your data from your layout. (smarty.net)

pritaeas
Posting Expert
Moderator
5,484 posts since Jul 2006
Reputation Points: 653
Solved Threads: 875
 

Hey yea, that's actually what I tried doing with something that I found on w3schools. Except it was to show 2 column names at same time. But whatever. I couldn't get it to work. But I think I just figured it out. I put what you just told me to put in and it WORKED! OMG I love you! I have been trying to get data to show up for MONTHS! I just couldn't find the php that it took to connect to my database! Ahhhh this is a happy day.

Ok ok ok, so, how do I be hands on with my data? Like Right now it shows that one column when you go to that specific page. But, how do I stay on that same page and have a link clicked to show a different column? I'll try to figure it out myself now that I know the basics it will make it soo much easier. I want to get all the links set up first though before I try to make the data fancy.

Also another question. Is it possible to store images in a database? Can't figure it out in CPanel but it must be possible cuz I know that places that sell merchandise the images of them are stored in databases.

Spunky
Light Poster
34 posts since Jun 2009
Reputation Points: 10
Solved Threads: 0
 

I just want to add I guess I don't exactly have to have the data on the same page change..or maybe I want to I'm not sure. See, with most other fansites when you search for things you can specify your search and it will show what you want..well that might be a little more advanced but, the point is, it shows up on the same page no matter what you choose you want to search for. The only thing that changes is the content that shows up.

Spunky
Light Poster
34 posts since Jun 2009
Reputation Points: 10
Solved Threads: 0
 

Glad to see you got it to work.

Images can be stored in a varbinary field, or you store the image on the server as file, and put only the filename as string in the db.

I'm not quite sure what you want to achieve with your links. Could you give a small example?

pritaeas
Posting Expert
Moderator
5,484 posts since Jul 2006
Reputation Points: 653
Solved Threads: 875
 

Ok I see where to select the type to be Varbinary, but, how do I actually get an image in there?? Hehe.

Also ok umm. Well. At least to my knowledge the page doesn't really change but tell me if I am wrong and if it is possible to do what I want to do. I want when the main page loads it says something, like, explaining what the page is for. Then when you click on something, that text changes into the information that you clicked on. Small visual go to http://www.wowtah.com/achievements.php#main . Right now the data in there is what I chose to test with using your help. But, when the person first visits that page say in place of that data it's explaining what achievements are. Then when you click on the links off to the left (General, Quests, Exploration, all those) that data changes and shows you the achievements in that category. Is this possible? I mean, if I had to put each category on a new page then I don't understand the point in using a database for this. I thought to use one so that I didn't have to make a page for each one.

An example of something I am trying to achieve is go here: http://www.wowhead.com/?npcs=1 you will see it says npcs=1 in the url at the top yes? Well if you hover over the NPCs link that is above the shown data, (Database>NPCS>Beasts) You can select something other than Beasts by going to NPCs in the drop menu and clicking Critters. Now in the url shows instead of npcs=1 it shows npcs=8. The rest of the page did not change. Just the data inside it. Perhaps this is a different concept than what I am trying to achieve, though, eventually I will need to do this because I am going to store that sort of searchable data as well.

I hope I've made it clear what I am trying to do. I don't know a whole lot about how databases work so, thats why it's a little hard to explain haha.

Also I just tried creating a new table to test the Varbinary type field and, wasn't able to create it. Got error: #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'NOT NULL) ENGINE = MyISAM' at line 1. But I think it could be just cuz I am not filling in the other fields correctly. Like heres the SQL it showed for the fields I filled:

CREATE TABLE `wowtahc1_achievements`.`test` (
`Images` VARBINARY NOT NULL
) ENGINE = MYISAM


Is there something I need to put in the others like the Length/Values, Collation or Attributes?

Spunky
Light Poster
34 posts since Jun 2009
Reputation Points: 10
Solved Threads: 0
 

Ok I actually did a bit of research. I added 255 to the length like I would for a VARCHAR field and got it to create. But how do I get an image in it when I try to insert data?

Spunky
Light Poster
34 posts since Jun 2009
Reputation Points: 10
Solved Threads: 0
 
pritaeas
Posting Expert
Moderator
5,484 posts since Jul 2006
Reputation Points: 653
Solved Threads: 875
 

You know. I've really appreciated your help up until here but that link was just a disappointmet.

1.) Have I not made it clear I don't know the coding yet for PHP? That link brought me to people discussing code and how to fix or add to the code. I noticed the dude used XAMPP which, I tried using to make a server on my computer but failed so instead bought a host that did it for me.

2.) I need to know how to do this through CPanel if possible and with as little self coding as possible. Obviously if I need to code I need to code, I am willing to learn. But I can't look at that post you linked and learn.

The guy on that post and I may have a similar issue but we are both on different levels of the issue and knowledge. I understand I may need more knowledge, but I don't know it yet till I know how to do what.

Do you know how to use CPanel? Cuz really that's what I came on this forum for, to find someone that knows CPanel that can help me out.

Spunky
Light Poster
34 posts since Jun 2009
Reputation Points: 10
Solved Threads: 0
 

Probably misunderstood, possibly because english is not my native language, but I'm trying. Uploading an image through phpMyAdmin (in cpanel) can be done by using the choose file button, when you insert a new record. this works on varbinary and blob fields.

pritaeas
Posting Expert
Moderator
5,484 posts since Jul 2006
Reputation Points: 653
Solved Threads: 875
 

Oh and sorry for coming off harsh. Hadn't realized you english isn't the best. It's alright you misunderstood.

I hadn't seen a choose file button when I looked before and I just looked again now that I know to look for one and still don't see anything. Where is it located? I am inserting a new field into the table that has a Varbinary field. I can change the function and type in the value field, but that is all I see.

Spunky
Light Poster
34 posts since Jun 2009
Reputation Points: 10
Solved Threads: 0
 

Doesnt matter. I can understand your frustration. Create a table containing a blob field (not varbinary, my mistake). Then you can insert data in the table. I made a screenshot so you can see:

http://pritaeas.info/DaniWeb/Screenshot/DatabaseCPanel.png

pritaeas
Posting Expert
Moderator
5,484 posts since Jul 2006
Reputation Points: 653
Solved Threads: 875
 

Omg thank you!! You are so helpful! Thank you so much!

Ok so now I still need to know how to change my data when a link is clicked on. I'm sure you haven't answered that because I'm probably still confusing.

Go to http://www.wowtah.com/achievements This is my website; particularily the page I am specifically working on. See those yellow words off to the left? Those are the different categories of the different achievements you can aquire. The data in the middle currently is just the test data I put there with your help. Eventually I will make it so it introduces you to what achievements are and blah blah blah but then when you click on one of the categories it will list those achievements.

What I am trying to accomplish is like on http://wowhead.com they have a huge database of stuff you can sift through. And no matter what you click on the rest of the page stays the same. As if only the data is changing. Or am I wrong? Is everything else perhaps in a template that is used over and over again? My site is created with a template ofcourse. But, with a database, how do I have people search through it then like on wowhead without having a new page for each thing they search for? I notice that the url changes only slightly at the top, like the number at the end when you search. Just like on this website, everything stays the same except the post number.

Do you see what I mean? I am doing my best to explain lol. I guess I am just not all that familiar with how websites go about having their databases searched within. I'm still new to this.

I guess wowhead also has their data organized in a different way than I am trying to do. More in lists. But I am sure that's all customizable. I just need to know how its done first..I dont know how else to explain what I am trying to do. If you dont understand exactly, ask any questions that may help.

Spunky
Light Poster
34 posts since Jun 2009
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You