OK the table "users" in my database looks like this:
id|username|name |email|points|type
--|-------------|---------|-------|-------|-------
0|person1 |name |.........|0 |admin
1|person2 |name2|.........|0 |admin
(points field is for rewards + counting what stuff someone has done)
I want to be able to edit, say, person1 (ID 0) and change his type to "user" because he has abused his admin powers (let's say) I have created a page called "editusers.php" in a .htaccess protected dir. I can delete user "person1" very easily and it works... but with editing him it doesn't work... This is the form handling code (1/2 a php page, MySQL is allready connected and the db is alreaduy selected)
<?php
// Process form...
$id = $_POST['id'];
$username = $_POST['username'];
$name = $_POST['name'];
$email = $_POST['email'];
$type = $_POST['type'];
$points = $_POST['points'];
$delete = $_POST['delete'];
// Connect to DB
$mysqlConnect = mysql_connect(localhost, peccamo9_root, secret1904);
// Select DB
mysql_select_db(peccamo9_points);
// Create query
$query = "UPDATE `users` SET `id` = '$id'";
if(isset($username)){
$query .= ", `username` = '$username'";
}
if(isset($name)){
$query .= ", `name` = '$name'";
}
if(isset($email)){
$query .= "`email` = '$email'";
}
if(isset($points)){
$query .= ", `points` = '$points'";
}
if(isset($type)){
$query .= ", `type` = '$type'";
}
$query .= "WHERE `id` = $id";
if(isset($delete)){
// Over-write query
$query = 'DELETE FROM users WHERE id = ' . $id;
}
// Run query
$hasWorked = mysql_query($query);
// Do error reporting where nessesary
if($hasWorked == 'TRUE'){
echo "User $username added to database<br />Name: $name<br />Email: $email<br />Type: $type<br />Points: $points";
}
elseif($hasWorked == 'FALSE'){
echo 'A MySQL error occured: ' . mysql_error() . "<br />\n" . 'Please inform Isaac';
}
else{
echo 'A PHP error occured, if it is visible on the page please contant Isaac with the information, otherwise, just tell Isaac<br />' . "\n";
}
echo '$delete = ' . $delete . "\n";
// End!
?>
The trouble is, my lovely built-in error handling returns the last message ("A PHP error occured.....") nothing is displayed by PHP, no Fatal Error or Warning, just my thing, and, when checking with phpMyAdmin, nothing has happened to the database.
I'm sure this error is very easy to sort out if you are an expert, but I, sadly, am not one (YET!!!), I hope one of you will be able to help