musicman07 Posted December 4, 2010 Posted December 4, 2010 I am new to Heliohost as I am learning PHP and MYSQL. I con't quite see how to set up a database using MYSQL. I entered the following code which worked in WAMP Server but not my Heliohost site (html code was an afterthought). <html> <body bgcolor = "#0000f>" <font color = #fffff"> <?php require("connect.php"); mysql_query("CREATE TABLE `phpacademy`.`people` ( `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY , `firstname` VARCHAR( 25 ) NOT NULL , `lastname` VARCHAR( 30 ) NOT NULL , `dob` DATE NOT NULL , `gender` VARCHAR( 1 ) NOT NULL )"); mysql_query("INSERT INTO `phpacademy`.`people` (`id`, `firstname`, `lastname`, `dob`, `gender`) VALUES (NULL, 'John', 'Headen', '1989-07-12', 'M'), (NULL, 'Emily', 'Headen', '1988-09-12', 'F')"); $extract = mysql_query("SELECT * FROM people ORDER BY id ASC"); $numrows = mysql_num_rows($extract); echo "<br>"; while ($row = mysql_fetch_assoc($extract)) { $id = $row['id']; $firstname = $row['firstname']; $lastname = $row['lastname']; $dob = $row['dob']; $gender = $row['gender']; echo ("<br>$firstname $lastname was born in $dob"); } ?> <br><br>What we see here is a basic example of editing a PHP site using Mysql to retrieve info from the database. </body> </html> It is not working on Heliohost though. The Connect part works and the echo statements are working fine, but clearly the data is not being saved and retrieved. I am puting everything in public_html and uploading with CoffeeCup Direct FTP. Quote
Wizard Posted December 4, 2010 Posted December 4, 2010 Did you create a database and add a user to it? What are the names that you're using for the database and user? Do you give correct permissions when you added the user to the database? Quote
musicman07 Posted December 4, 2010 Author Posted December 4, 2010 Cheers Wizard. No I don't think I did any of that. Where does it tell you how to do this in Heliohost? I assume the mysql_query commands are creating a database somewhere on the server. How to I assign user privileges? Quote
Wizard Posted December 4, 2010 Posted December 4, 2010 It seems like you're new to MySQL and PHP. You should read through this: http://w3schools.com/php/php_mysql_intro.asp On cPanel, there is a MySQL wizard. Going through that will create a database and user for you. Quote
musicman07 Posted December 5, 2010 Author Posted December 5, 2010 Thanks for the link. New to PHP yes. I have done SQL before but the setting up users was not something we could practise (this being in Oracle). Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.