SO I am trying to build a very simple (semi) emailing system simply for practice and learning.
SO I have my nav bar with users personal info loading on the body (right side). Inside the nav bar there are clickable links to allow user to compose, read messages etc.
The links are appended with a PHP parameter as follows.
<a href="body.php?action=compose">
In the image below it is just a page load so for debugging purposes I use get not set, since no action has been taken (link clicked)
Now when user wants to compose an email and clicks compose, the following happens:
MY Logic
I get the action user wants to take via parameter appended to url in this case compose, so up comes a form allowing user to compose / sent a message to another user, which looks as follows:
I achieve this by the following code:
if($_SERVER['REQUEST_METHOD'] == 'GET'){
if(isset($_GET['action'])){
//get which action user wants to take in this example compose email
$action = $_GET['action'];
if($action == 'compose'){
?>
<form name="composeMsg" method="post" id="composeMsg" action="">
<input type="text" name="receipnt" placeholder="Receipnt" id="from">
<div class="break"></div>
<input type="text" name="subject" placeholder="Subject" id="subject">
<div class="break"></div>
<textarea placeholder="Message" name="msgBody" style="width: 350px; height: 200px">
</textarea>
<div class="break"></div>
<button type="submit" name="sendMsg" class="btn btn-danger">SEND</button>
</form>
<?php
}
//submit button has been clicked
if(isset($_POST['sendMsg'])){
//execute script to send msg
$check = $msgClass->composeMsg('14', $_POST['receipnt'], $_POST['subject'], $_POST['msgBody'], date('Y-m-d') );
if($check == true){
echo '<h1>MSG SENT!</h1>';
}
elseif($check == false){
echo '<h1>OOPS...SOMETHING WENT WRONG!</h1>';
}
}//isset msgSent
My problem
All I get when sending message is a reloaded screen. No error, No Warnings and no script execution so I really dont know where to start my debugging.
I have tried to create a test page with just the email form and my composeMsg()
method, which worked and inserted data into db. But when I implement it into my main page, when submit is clicked page just reloads without any action (as mentioned).
I have tried setting the form method to $_GET instead of $_POST but still same result
Any help appreciated!
Additional INfo
My method for send message looks as follows which is correct:
public function composeMsg($userID, $toUser, $subject, $msg, $senton ){
$db = DB::getInstance();
$sql = "INSERT INTO messages (userID, fromID, subject, body, senton) values (:userID, :toUser, :subject, :msg, :senton )";
$stmnt = $db->prepare($sql);
$stmnt->bindValue(':userID', $userID);
$stmnt->bindValue(':toUser', $toUser);
$stmnt->bindValue(':subject', $subject);
$stmnt->bindValue(':msg', $msg);
$stmnt->bindValue(':senton', $senton);
$stmnt->execute();
if($stmnt->rowCount() > 0){
return true;
}
else{
return false;
}
}