I've been following this nice tutorial, and I've been trying to implement some things into one of its examples so I can use it for my site. Its just a simple thing where it accesses some info from a MySQL database and then displays it in a list, and you have the option of adding information to it or removing from it. What I have been trying to do is make is so you have to use a password to remove from it. I can not get the information ID variable to transfer from the password page to the part where it deletes the information (it has to know which item it is to delete it). I'm using form action HTML for the password page along with PHP, and I need to know how I can get it to transfer the variable of what the ID is when you click on the submit button. Err, some of the variables might be confusing because in the tutorial's example it's a database of "jokes." Ignore the comments... Here is my code:
<HTML>
<HEAD>
<TITLE> Information </TITLE>
<HEAD>
<BODY>
<?php
// Connect to the database server
$dbcnx = @mysql_connect(
"localhost", "rosemont_mark", "mark");
if (!$dbcnx) {
echo( "<P>Unable to connect to the " .
"database server at this time.</P>" );
exit();
}
// Select the information database
if (! mysql_select_db("rosemont_general") ) {
echo( "<P>Unable to locate the information " .
"database at this time.</P>" );
exit();
}
// If a joke has been submitted,
// add it to the database.
if ("SUBMIT" == $submitjoke) {
$sql = "INSERT INTO information1 SET " .
"infotext='$joketext', " .
"infodate=CURDATE()";
if (mysql_query($sql)) {
echo("<P>Your information has been added.</P>");
} else {
echo("<P>Error adding submitted information: " .
mysql_error() . "</P>");
}
}
// If information has been deleted,
// remove it from the database.
if (isset($deletejoke)) {
?>
You must insert a password to delete information number
<?php
echo ("$deletejoke");
?>.
<FORM ACTION=<?php echo("$PHP_SELF"); ?> METHOD=GET>
Password: <INPUT TYPE=TEXT NAME="password">
<INPUT TYPE=SUBMIT VALUE="Continue">
</FORM>
<?php
if($password=="tequila") {
echo("<p>Password is correct.");
$sql = "DELETE FROM information1 " .
"WHERE ID=$deletejoke";
if (mysql_query($sql)) {
echo("<P>The information has been deleted.</P>");
}
if($password!="tequila" and isset($password)) {
echo("<p>Password is incorrect.");
}
}
else {
echo("<P>Error deleting information: " .
mysql_error() . "</P>");
}
}
echo("<P> Here is all the information " .
"in our database: </P>");
// Request the ID and text and date of all the information
$result = mysql_query(
"SELECT ID, infotext, infodate FROM information1");
if (!$result) {
echo("<P>Error performing query: " .
mysql_error() . "</P>");
exit();
}
// Display the text of each joke in a paragraph
// with a "Delete this Information" link next to each.
while ( $row = mysql_fetch_array($result) ) {
$jokedate = $row["infodate"];
$jokeid = $row["ID"];
$joketext = $row["infotext"];
echo("<P>$jokedate - " .
"$joketext " .
"<A HREF='$PHP_SELF?deletejoke=$jokeid'>" .
"Delete this information</A></P>");
}
// When clicked, this link will load this page
// with the joke submission form displayed.
echo("<P><A HREF='$PHP_SELF?addjoke=1'>" .
"Add information.</A></P>");
?>
</BODY>
</HTML>