Hi, Im having problems with a basic database script. Basically, I have two pages: KyanHome.php and KyanACP.php. Here is KyanHome.php:
[php]
Kyan's Name Database <?php $username="*"; $password="*"; $database="*"; function printForm() { ?>This is the perfect chance to submit your name to our database, and NOT be entered into one of those annoying free monthly prize draws that nobody ever wins.
Please type your first name here:
Please type your surname here:
<?php }if ( ! isset( $_POST[‘firstname’] ) and ! isset( $_POST[‘surname’] ) ) {
print “
Welcome!
”;printForm();
} else if ( empty( $_POST[‘firstname’] ) or empty( $_POST[‘surname’] ) ) {
print “
Error!
”;print “Please enter both a first name and a surname.”;
printForm();
} else {
$firstname = $_POST[‘firstname’];
$surname = $_POST[‘surname’];
$link = mysql_connect( “localhost”, $username, $password );
if ( ! $link ) {
die( "Couldn’t connect to MySQL: ".mysql_error() );
}
mysql_select_db( $database ) or die ( "Couldn’t open $database: ".mysql_error() );
$query = “INSERT INTO details(firstname, surname) VALUES ( ‘$firstname’, ‘$surname’)”;
mysql_query( $query, $link );
mysql_close( $link );
print “
Thanks!
”;print “Thanks for submitting your information to our database, $firstname $surname!”;
}
?>
Admin CP
Please enter the password to access the Admin Control Panel:
[/php]ANd KyanACP.php:
[php]
Kyan's Name Database ACP <?php // Only allows access to those who have entered the password at some point, or // arrived through pressing the delete button. if ( ! isset( $_POST['ACPpassword'] ) or $_POST['ACPpassword'] != "guess" or ( isset($_POST['deletebutton']) and $_POST['deletebutton'] == false) ) { print 'Access Denied
'; // Prints the entry portal if access is denied ?>Admin CP
Please enter the password to access the Admin Control Panel:
<?php // Prints the Admin CP } else { ?>Welcome to the ACP!
From here you can view and delete details added to the database!
<?php $username="*"; $password="*"; $database="*"; $link = mysql_connect( "localhost", $username, $password ); if ( ! $link ) { die( "Couldn't connect to MySQL: ".mysql_error() ); } mysql_select_db( $database ) or die ( "Couldn't open $database: ".mysql_error() ); $results = mysql_query( "SELECT * FROM details" ); $num_rows = mysql_num_rows( $results ); ?> ">No. | First Name | Surname | Delete |
---|---|---|---|
".stripslashes($field)." | "; } print "
You can see my script in action here: http://www.triwebs.com.ru/PHP/Kyan/KyanHome.php and http://www.triwebs.com.ru/PHP/Kyan/KyanACP.php (the password to the ACP is “guess”).
The problem (yes, were finally getting there), is that my delete function wont work.
I can see why, but it would be too confusing to explain, its to do with the id fields not corresponding to $checkbox because the ID field auto-increments.
Can someone help?[/url][/code]