How to enter PHP code for accessing mySQL database tables
-
How to enter PHP code for accessing mySQL database tables
I’m trying to connect to my Database table, retrieve the data, and display it on my web page (not a blog page). The problem is that I don’t know where to enter the php code to establish a connection with my database. Do I:
enter the php code by editing the individual page?
need to create a new php file (exaple: database_connect.php) and add it to my Templates via my host (hostgator) and ftp account (filezilla)?
need to edit my stylesheet (css)? If so, where in the stylesheet should the php code need to be inserted (header, body, etc.)?I have the latest version of WordPress. Hostagator hosts my WordPress files, Filezilla is my ftp account, and I’m using “A Simple Love (a child theme of the “Thematic” theme)” as my theme.
Note: I don’t have a problem executing a php test file that I created. The file is located in /public_html/test-php-files. Thus, I can enter the url as https://giftsrus.org/test-php-files/connectionfile.php and I get the result that says “If there are no errors in connecting to the database this is the only line you should see.:-)”
The php code within the in the connectionfile.php is as follows and seems to work:
<?php
$dbc = mysql_connect (‘localhost’,’tank2010_bucky20′,’password<>’);if (!dbc) {
die(‘Not Connected:’ . mysql_error ());
}$db_selected = mysql_select_db (‘tank2010_test-csv’, $dbc);
if (!$db_selected) {
die (“Can’t Connect :” .mysql_error());
}$query=”UPDATE game SET email=’I hope – this code works’ WHERE username=’bucky20′”;
//add “result”
$result=mysql_query($query);if (!$query) {
die (“Can’t Connect :” .mysql_error());
}echo “If there are no errors in connecting to the database this is the only line you should see.:-)”
?>
So, I don’t know where to place this code to connect to my database automatically when the web site comes up. Do I go through ‘Appearance > Editor and edit the css stylesheet, template, or what.arance>
Any help would be greatly appreciated.
- The topic ‘How to enter PHP code for accessing mySQL database tables’ is closed to new replies.