...

View Full Version : Some problems...



Zegg90
02-16-2006, 05:37 PM
I have a PHP function that posts a message to a database, and forwards the user to another page, making it look like the page hasn't changed:

index.php -> process.php
process.php adds message to database
process.php -> index.php
index.php -> shows the message

The function is this:


//Insert message
function insertmsg($message, $username, $db) {
$check1 = $db->execute("select `id`, `message` from `messages` where `username`=?", array($username));
$check = $check1->fetchrow();
if (!$check) {
$insert['message'] = $message;
$insert['username'] = $username;
$insertmsg = $db->autoexecute('messages', $insert, 'INSERT');
if (!$insertmsg) {
return false;
} else {
return true;
}
} else {
$currentmsg = $check['message']."\n<BR>".$message;
//$currentmsg .= "\n".$message;
$updatemsg = $db->execute("update `messages` set `message`=? where `username`=?", array($currentmsg, $username));
if (!$updatemsg) {
return false;
} else {
return true;
}
}
}


At the top of every page, it shows this:


<?php
$message1 = $db->execute("select `id`, `username`, `message` from `messages` where `username`=?", array($stats->username));
$message = $message1->fetchrow();
if ($message) {
echo "<BR><center><B>".$message['message']."</B></center><BR><BR>\n";
$delete = $db->execute("delete from `messages` where `username`=?", array($stats->username));
//$delete = "1";
if (!$delete) {
echo "Error!<BR>\n";
echo $db->error();
include("includes/footer.php");
exit;
}
}
?>


For some reason, the message is never shown, but the record has been in there and deleted as well, I can see that by the index number and the overhead... Does anybody know why the mesage isn't being shown?


This is what is being inserted:


$msg1 = "You bought a ".$insert['item_name']." for ".$check['cost']." gold!<BR><BR>\n";
insertmsg($msg1, $stats->username, $db);

Thanks! :D



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum