Help for a PHP new commer
Posted: Tue Nov 24, 2009 2:07 pm
hello all.
I have been banging my head against a hard wall. I am new to PHP, and would like to use it so I can make my site dynamic.
I have some code which I would like some help on.
I have been told it is messy but I am new and was following a tutorial.
Basically, I am trying to use TinyMCE to edit, save, and update data on MySQL database
Could someone take pitty on a new chap and help me out?
Basically I would like to tidy it up, and solve the issue I have, which is it doesn't save back to my database.
Now because it is whilst i was following a tutorial the comments are slightly out.
DB name is yellowz1_rtb, table it is linked to is TestText.
Please help
I have been banging my head against a hard wall. I am new to PHP, and would like to use it so I can make my site dynamic.
I have some code which I would like some help on.
I have been told it is messy but I am new and was following a tutorial.
Basically, I am trying to use TinyMCE to edit, save, and update data on MySQL database
Code: Select all
<form action="<?=$_SERVER['PHP_SELF']?>" method="post">
<!--<form method="post" method="post">-->
<textarea name="TestText" cols="50" rows="15">
<?
//if (isset($_GET['addtest'])): // If the user wants to add a joke
//else: // Default page display
//Connect to database server
$dbcnx = @mysql_connect('localhost', 'USERNAME', 'PASSWORD');
if (!$dbcnx) {
die( '<p>Unable to connect to the ' .
'database server at this time.</p>
<p>Please try again later</p>
<p>If this continues to happen, please contact your system administrator</p>' );
}
// Select the jokes database
if (! @mysql_select_db('yellowz1_rtb') ) {
die( '<p>Unable to locate the Round The Bend ' .
'database at this time.</p>' );
}
// If a joke has been submitted,
// add it to the database.
if (isset($_POST['submittest'])) {
$testtext = $_POST['testtext'];
$sql = "INSERT INTO Testimonials SET
TestText='$testtext'
";
if (@mysql_query($sql)) {
echo('<p>Your Testimonial has been added.</p>');
} else {
echo('<p>Error adding submitted joke: ' .
mysql_error() . '</p>');
}
}
/* echo('<p> Here are all the Testimonials in our database: </p>');
// Request the text of all the jokes
$result = @mysql_query('SELECT TestText FROM Testimonials');
if (!$result) {
die('<p>Error performing query: ' .
mysql_error() . '</p>');
}
// Display the text of each joke in a paragraph
while ( $row = mysql_fetch_array($result) ) {
echo('<p>' . $row['TestText'] . '</p>');
}
// When clicked, this link will load this page
// with the joke submission form displayed.
echo('<p><a href="' . $_SERVER['PHP_SELF'] .
'?addtest=1">Add a Testimonial!</a></p>');
endif;*/
?>
</textarea>
<input type="submit" name="submitjoke" value="SUBMIT" />
</form>Basically I would like to tidy it up, and solve the issue I have, which is it doesn't save back to my database.
Now because it is whilst i was following a tutorial the comments are slightly out.
DB name is yellowz1_rtb, table it is linked to is TestText.
Please help