Jump to content
grlayouts

Form update, no error.

Recommended Posts

If anyone could help, I'm not getting an error message and I've tried changing the code around a few times and outputting errors.

The database does not update and i'm getting no error message output on submit, I assume i'm missing something?
 
<?php
session_start();
include_once 'dbconnect.php';


if (!isset($_SESSION['userSession'])) {
header("Location: index.php");
}


$query = $DBcon->query("SELECT * FROM tbl_users WHERE user_id=".$_SESSION['userSession']);
$userRow=$query->fetch_array();




?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Welcome - <?php echo $userRow['email']; ?></title>


<link href="bootstrap/css/bootstrap.min.css" rel="stylesheet" media="screen"> 
<link href="bootstrap/css/bootstrap-theme.min.css" rel="stylesheet" media="screen"> 


<link rel="stylesheet" href="style.css" type="text/css" />
</head>
<?php include_once 'header.php'; ?>


<html>
<head></head>
<body>
<h1>Send Message:</h1>
<form action='message.php' method='POST'>
<table>
<tbody>
<tr>
<td>To: </td><td><input type='text' name='to' /></td>
</tr>
<tr>
<td>From: </td><td><input type='text' name='from' /></td>
</tr>
<tr>
<td>Message: </td><td><input type='text' name='message' /></td>
</tr>
<tr>
<td></td><td><input type='submit' value='Create Task' name='sendMessage' /></td>
</tr>
</tbody>
</table>
</form>
</body>
</html>






<?php






if (isSet($_POST['sendMessage'])) {
if (isSet($_POST['to']) && $_POST['to'] != '' && isSet($_POST['from']) && $_POST['from'] != '' && isSet($_POST['message']) && $_POST['message'] != '') {
$to = $_POST['to'];
$from = $userRow['email'];
$message = $_POST['message'];


$q = "INSERT INTO tbl_messages(id,message,to,from) VALUES('', '$message', '$to', '$from')";


if ($DBcon->query($q)) {
$msg = "<div class='alert alert-success'>
<span class='glyphicon glyphicon-info-sign'></span>   Message Sent !
</div>";
}else {
$msg = "<div class='alert alert-danger'>
<span class='glyphicon glyphicon-info-sign'></span>   Message not Sent! !
</div>";
}
}
}
$DBcon->close();?>


<?php php include_once 'footer.php'; ?>


</html>

 

Share this post


Link to post
Share on other sites

If your id value on the database is an autoincrement key, then don't put it into your insert statement.

Share this post


Link to post
Share on other sites

The following block of code assigns the message to a variable:

if ($DBcon->query($q)) {
    $msg = "<div class='alert alert-success'>
    <span class='glyphicon glyphicon-info-sign'></span>   Message Sent !
    </div>";
}else {
    $msg = "<div class='alert alert-danger'>
    <span class='glyphicon glyphicon-info-sign'></span>   Message not Sent! !
    </div>";
}
 
You need to echo/print $msg for the message to appear on screen.  :happy-04:

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.