I started last night with PHP Scripting, thanks to Mr. Yank I was able to get a pretty quick grasp on the logic associations of interaction between PHP and MySQL.
Now I created a very simple example of a DB driven page (some of you will crack up)...you can see it http://www.cte-networks.com/test.php . So I was able to put in the admin section the ability to input text onto the "test.php"...no problem with that. But how can I modify the Admin section so when I enter the section, I see in the Text Boxes the already existing Text and I can delete, edit or add text to the database...sorry I know it is probably the easiest thing to do, but don't forget I am only 1 day old in PHP and MySQL. Here is the Code I am currently using in the Admin Section:
<FORM ACTION="<?php echo($PHP_SELF); ?>" METHOD=POST>
<P><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Type your Text
for the left column hereBR>
<TEXTAREA NAME="textleft" ROWS=10 COLS=40 WRAP>
</TEXTAREA>
</font><BR>
<INPUT TYPE=SUBMIT NAME="submittext1" VALUE="SUBMIT">
</FORM>
<?php
// Connect to the database server
$dbcnx = @mysql_connect("localhost",
"root", "password");
if (!$dbcnx) {
echo( "<P>Unable to connect to the " .
"database server at this time.</P>" );
exit();
}
// Select the test database
if (! @mysql_select_db("dbname") ) {
echo( "<P>Unable to locate the joke " .
"database at this time.</P>" );
exit();
}
// If a text has been submitted,
// add it to the database.
if ("SUBMIT" == $submittext1) {
$sql = "INSERT INTO test1 SET " .
"TextLeft='$textleft' ";
if (mysql_query($sql)) {
echo("<P>Your Text has been added.</P>");
} else {
echo("<P>Error adding submitted text: " .
mysql_error() . "</P>");
}
}
?>
<FORM ACTION="<?php echo($PHP_SELF); ?>" METHOD=POST>
<P><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Type your Text
for the right column hereBR>
<TEXTAREA NAME="textright" ROWS=10 COLS=40 WRAP>
</TEXTAREA>
</font><BR>
<INPUT TYPE=SUBMIT NAME="submittext2" VALUE="SUBMIT">
</FORM>
<?php
// Connect to the database server
$dbcnx = @mysql_connect("localhost",
"root", "password");
if (!$dbcnx) {
echo( "<P>Unable to connect to the " .
"database server at this time.</P>" );
exit();
}
// Select the test database
if (! @mysql_select_db("dbname") ) {
echo( "<P>Unable to locate the joke " .
"database at this time.</P>" );
exit();
}
// If a text has been submitted,
// add it to the database.
if ("SUBMIT" == $submittext2) {
$sql = "INSERT INTO test2 SET " .
"TextRight='$textright' ";
if (mysql_query($sql)) {
echo("<P>Your Text has been added.</P>");
} else {
echo("<P>Error adding submitted text: " .
mysql_error() . "</P>");
}
}
?>
<p><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><a href="test.php">Go
back to Test Site</a></font></p>
</body>
</html>
Have you heard the saying, "A little knowledge is a dangerous thing"? I think it applies in this situation.
May I suggest that you continue reading my article. Chapter 6 in particular treats effective design of content management systems, and provides copious examples (including downloadable sample code) of forms for adding, editing, and deleting database entries. You really need to look at more examples to better understand how to design and structure database-driven pages using PHP. In your code above, for example, you are connecting to the same MySQL server and selecting the same database twice for no reason.
If after reading you find you're still stuck, please feel free to ask for help!
Incidentally, the URL you provided gives me an internal server error...
Bookmarks