as4s1n
New Member
- Messages
- 174
- Reaction score
- 4
- Points
- 0
I was working on a private message system and I ran into a huge problem. Whenever they go to send a message, they get a custom error message and I get an error that reads Resource error #6.
Here is my code:
FYI:
writeError() is a PHP function to handle errors that writes a message to a file and displays a custom error message.
Here is my code:
PHP:
<?php
$toUsers = explode(',',$_REQUEST['toUser']);
$subject = $_REQUEST['subject'];
$message = $_REQUEST['message'];
$date = date('m/d/y @ h:i:s');
$badMessage = 0;
$error = '';
if(trim($toUsers) == '') {
$badMessage++;
$error .= "Invalid 'TO'";
}
if(trim($subject) == '') {
$badMessage++;
$error .= "Invalid 'SUBJECT'";
}
if(trim($message) == '') {
$badMessage++;
$error .= "Invalid 'MESSAGE'";
}
if($badMessage > 0)
echo "Error with your message: $error";
else {
$curUser = $_SESSION['loggedin'];
$query = "SELECT id FROM users WHERE username = '$curUser'";
$result = mysql_query($result);
if(!$result)
writeError(mysql_error());
else {
while($row=mysql_fetch_array($result, MYSQL_ASSOC)) {
$senderID = $row['id'];
}
}
if(sizeof($toUsers) != 1) {
$query = "SELECT id FROM users WHERE username = '$toUsers'";
$result = mysql_query($query);
if(!$result)
writeError(mysql_error());
else if(mysql_num_rows($result) === 0)
echo "Cannot find user";
else {
while($row=mysql_fetch_array($result, MYSQL_ASSOC)) {
$toID = $row['id'];
$query = "INSERT INTO mail VALUES(0,'$toID','$senderID','$subject','$message','$date')";
$result = @mysql_query($query);
if(!$result)
writeError(mysql_error());
else {
echo "Message(s) sent!";
}
}
}
} else {
for($i=0;$i<sizeof($toUsers);$1++) {
$users = $toUsers[i];
$query = "SELECT id FROM users WHERE username = '$users'";
$result = @mysql_query($query);
if(!$result)
writeError(mysql_error());
else if(mysql_num_rows($result) === 0)
echo "Cannot find user";
else {
while($row=@mysql_fetch_array($result, MYSQL_ASSOC)) {
$toID = $row['id'];
$query = "INSERT INTO mail VALUES(0,'$toID','$senderID','$subject','$message','$date')";
$result = @mysql_query($query);
if(!$result)
writeError(mysql_error());
else {
echo "Message(s) sent!";
}
}
}
}
}
}
?>
FYI:
writeError() is a PHP function to handle errors that writes a message to a file and displays a custom error message.