Hey people, i have used this code which a friend gave me, i have tried to integrate it into my own little test project, however i keep on getting a
Fatal error: Can't use function return value in write context on line 30 (the one in bold)
can anyone help please, or is there a simpler code, which will allow me to delete a user from a database
Thanks
<?php
session_start();
$connect = mysql_connect("localhost", "root", "")
or die("Hey loser, check your server connection.");
//make our database active
mysql_select_db("test");
$msg = "are you sure?"; // var to hold delete status
$username = addslashes($_POST['username']);
if (strlen(trim($username)) > 0) {
// your script here to delete user
// in dabase taking $iusername as argument
if(isset($_POST['delete_user']) && isset($_POST['username']) && isset($_POST['sure'])){
$d_sql = " delete from user
where username = '$_POST[username]'";
$d_query = mysql_query($d_sql)
or die(mysql_error());
echo $d_sql;
$delete_success = true;
}
//$final_output = <<<EOF
// use these function to check if query outcome of last database operation
[B]if (mysql_affected_rows($d_query) = 0) [/B] {
// no record matching criterium(idno)
$msg = "NO such record exists.";
}
elseif (mysql_affected_rows($d_query) > 0) {
// delete successful
$msg = "Record deleted.";
}
else {
// error
$msg = "Error in operation.<br>";
$msg .= mysql_error();
}
}
?>
<html>
<head><title>Delete User</title></head>
<body>
<form action="" method="post">
<?=$msg?>
<br />
Enter Username<input type="username" value="">
<input type="submit" value="delete">
</body>
</html>