php/sql – Insert Data into Table with PHP (Bootstrap Form, if that makes a difference)

Bottom line: I don’t know what the hell I’m doing. I just want this comment box to submit information to my database. Let me show you what I got.

<form method="POST" action="post.php" style="font-
 size:200%;padding:50px">
<label for="comments">Comments:</label>
<textarea class="form-control" placeholder="How can I improve?" 
 style="background-color:#fff4c9;border-radius:15px;width:100%;" 
 name="comments" rows="5" id="comments" value=""></textarea> <br>
<button type="submit" class="btn btn-default">Share Your Ideas</button>
</form>`

and then my php i guess????

<?php
if($_SERVER["REQUEST_METHOD"] == "POST") {
$servername = "localhost";
$username = "id1403626_wp_4764008ac42f7398450c24184e47c38a";
$password = "Marshall2";
$dbname = "id1403626_wp_257ecd760342ffcefce424435ed4e776";
//Collect Value of Input Field
$name = $_POST['comments'];
$timestamp = date('Y-m-d H:i:sa');

//Create connection
$connect = mysqli_connect($servername, $username, $password);

//Check connection
if ($connect->connect_error) {
die("So here's the problem...:".$connect->connect_error);
}
//Select Database
mysqli_select_db($connect,$dbname)
or die("Whoops! Can't find that pesky database!");
//Insert Data Query
$sql = "INSERT INTO `Comments`(`comments`, `date`) VALUES ($name, 
$timestamp)";
//What should happen
$result = mysqli_query($connect, $sql);

if($result){
echo 'thank you for your feed back';
}else {
echo "Fuck man I can't code this shit right. If you have a comment email 
it to me at philobythekilo@gmail.com I'ma get this shit working one of 
these days.";
}
}
?>

I just cannot find what I am doing wrong. Help a sista out, please!


Source: stackoverflow-php

Strange bootstrap behavior with Chrome/Sierra

I’m under OSX Sierra, Chrome 57, Bootstrap 3.3.7, Font awesome 4.

The following :

<button type="button" class="btn btn-primary btn-md" data-loading-text="<i class='fa fa-circle-o-notch fa-spin'></i> wait">Go</button>

And the Js part :

$('.btn').on("click", (evt) => {
  $('.btn').button("loading");
});

Does not work correctly. But It works with Safari !?

Any idea or workaround ?


Source: stackoverflow-javascript

Displaying PHP success and fail messages with Ajax

What went wrong in this code? I ready many post here on this issue but can’t fix my error. I have the following.

HTML Code

    
It worked
It failed
</div>

PHP Code

if(!$stmnt->execute()){
            echo "Failed!";

        }else{
            echo "Inserted";
        }

AJAX Code

success: function(data){
        viewData();
        $('#addData').modal('hide');//close the modal.
        if (data=="Failed") {
            $("#failMessage").show();
            //console.log(data); is showing message from PHP
        } else{data=="Inserted"};
            $("#successMessage").show();
            //console.log(data); is showing message from PHP
       }

Problem: I would like to display the error in the page not in console. I want to inform the user. Why is it not working with $("#successMessage").show();?

PS: I am using Bootstrap. Also how can I show my messages using one(1) div="msg" tag?


Source: stackoverflow-php

jquery .show does not work

I have a left side navbar in bootstrap, when clicking on a menu I want to show a section with jquery.show. Can’t see why it doesn’t show up:

      <!DOCTYPE htwml 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">
   <meta charset="utf-8">
  <head>
      <title>Nav</title>

      http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js
      <link href="http://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.6/css/bootstrap.min.css"
          rel="stylesheet" type="text/css" />
      http://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.6/js/bootstrap.min.js



      <style media="screen">
      /* make sidebar nav vertical */
  @media (min-width: 768px) {
  .sidebar-nav .navbar .navbar-collapse {
    padding: 0;
    max-height: none;
  }
  .sidebar-nav .navbar ul {
    float: none;
  }
  .sidebar-nav .navbar ul:not {
    display: block;
  }
  .sidebar-nav .navbar li {
    float: none;
    display: block;
  }
  .sidebar-nav .navbar li a {
    padding-top: 12px;
    padding-bottom: 12px;
  }
  }
      </style>

      <style media="screen">
        .hidden {
          display: none;
        }

      </style>
  </head>
  <body>

    

Dynamic content in Bootstrap modal and dynamic data in Ajax [Laravel]

I have some problems while coding in Laravel, in particular with passing data to a modal (bootstrap framework) and passing data to an Ajax post request.
I have an array of items with an ‘id’, a ‘name’ and a ‘content’, that are retrieved from database and passed to the view. Below are the controller code and the view:
Controller:

<?php

namespace AppHttpControllers;

use IlluminateHttpRequest;


class SiteController extends Controller
{    
    public function index(){
    
    $items = AppItems::all();

    return view('home', compact('items'));
    }
}

View (index.blade.php)

@foreach ($items as $item)

{{ $item->name }}

</div> @endforeach

When I click on the ‘button’ Delete, it will shows a modal. Below the code:

Call modal if the condition is meet – PHP

Im trying to make the modal show in the condition is met but the problem is no modal is showing, can someone help me about this? The php code is below of the modal code.

here’s the php

<?php
                    session_start();
                    include_once("connection.php");
                    if(isset($_POST['login'])){
                        $stud_no = $_POST["stud_no"];
                      $password = $_POST["pword"];
                        $name = mysqli_real_escape_string($con, $stud_no);
                        $password = mysqli_real_escape_string($con, $password);
                        $select_user="SELECT * FROM student_accounts WHERE stud_no ='$stud_no' AND password ='$password'";
                        $run_user = mysqli_query($con, $select_user);
                        $check_user = mysqli_num_rows($run_user);
                        if($check_user > 0){
                        $_SESSION['stud_no'] = $stud_no;
                            header('location: home.php');
                        }

                        else{
                             echo '$("#myModal").modal()';

                        }
                    }

                    ?>

here’s the modal

How do I prevent the tab from changing

I am able to get into the function it calls the prevent and I return false but the tab still switches? Any ideas of what I am doing wrong?

<ul class="nav nav-tabs" id="templateActionTab">
       <li id="menuTemplateTab" class="active"><a data-toggle="tab" href="#templateTab">Template</a></li>
       <li id="menuAction"><a data-toggle="tab" href="#actionTab">Action</a></li>
       <li id="menuScheduler"><a data-toggle="tab" href="#schedulerTab">Scheduler</a></li>
</ul>


$(document).on('shown.bs.tab', 'a[data-toggle="tab"]', function (event) {


  var isValidationValid = templateInstance.validateScreen();

  if(isValidationValid)
  {
    localStorage.setItem('activeTab', $(event.target).attr('href'));
    $(event.target).attr("href");
    return true;
  }
  else
  {

    event.preventDefault();
    return false;

  }


});


Source: stackoverflow-javascript