grlayouts Posted March 8, 2017 Share Posted March 8, 2017 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> Quote Link to comment https://forums.phpfreaks.com/topic/303396-form-update-no-error/ Share on other sites More sharing options...
NigelRel3 Posted March 8, 2017 Share Posted March 8, 2017 If your id value on the database is an autoincrement key, then don't put it into your insert statement. Quote Link to comment https://forums.phpfreaks.com/topic/303396-form-update-no-error/#findComment-1543918 Share on other sites More sharing options...
grlayouts Posted March 8, 2017 Author Share Posted March 8, 2017 Got ya, It now inserts, but I get no success or failure message.. Quote Link to comment https://forums.phpfreaks.com/topic/303396-form-update-no-error/#findComment-1543919 Share on other sites More sharing options...
cyberRobot Posted March 8, 2017 Share Posted March 8, 2017 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. Quote Link to comment https://forums.phpfreaks.com/topic/303396-form-update-no-error/#findComment-1543923 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.