Hello there,
OKay, so I'm giving you a quick tutorial on how to do this in PHP.
When you first login to CPanel, there is a section (usually towards the bottom) called Databases. Click "MySQL Databases." Under "Create New Database", enter a database name. Create it and do the same for a user. Then add the user to a database. This is all done on the same MySQL Databases page.
Next, create a send.php and change the action attribute of the form on the homepage.. Then copy & paste this code in
PHP Code:
<?
$con = mysql_connect("localhost","USER","PASSWORD");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("DATABASE", $con);
?>
Recall back to when you created the user for the database, enter the username (don't forget it includes your account username with an underscore before). Replace the capitalized text with the correct information, don't forget DATABASE towards the bottom.
Next, create a createdb.php page.
Copy & paste the exact same MySQL connection from above at the top of this file with the filled in connection information, and then add this after.
PHP Code:
<?
# MySQL CONNECTION INFO
$sql = "CREATE TABLE IF NOT EXISTS `poem` (
`ID` INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`poem` VARCHAR( 255 ) NOT NULL
) ENGINE = MYISAM";
mysql_query($sql) or die(mysql_error());
echo "Database table successfully created.";
?>
Now visit createdb.php and if it says "Database table successfully created", then it was a success, if it doesn't say that, then there was an error. Please reply to this topic by posting it below.
Now your database is created.
Edit:
Now on your send.php page, you should have MySQL connection info at the top there. Add this after it
PHP Code:
<?
if(empty($_POST['message'])) {
echo "You must enter some characters.";
}
else {
$msg = mysql_real_escape_string($_POST['message']);
mysql_query("INSERT INTO `poem` (`poem`)
VALUES ('$msg')");
echo "Thank you for your poem line submission.";
echo "<br><br><a href='history.go(-1)'>Go back</a>";
}
?>
I assume under the "Our Poem" image on the homepage, you want the poem listed there, correct?
Well, this is what you do. Change your default/index page to index.php
Be sure to include your MySQL connection information again, and then add this after:
PHP Code:
<?
$entries = mysql_query("SELECT `poem` FROM `poem` ORDER BY ID DESC");
if(mysql_num_rows($entries) == 0) {
echo "There are no entries yet.";
}
else {
while($poem = mysql_fetch_array($entries)) {
echo "<i>$poem[poem]</i><br>";
}
?>
Hopefully that all works for you. None of this is tested, there is probably a stupid typo somewhere. But if you have any trouble, please reply here. Also, don't forget to delete createdb.php. Good luck!
nobackseat