PHP INSERT INTO函数在localhost上运行,但在我的Web服务器上运行

时间:2018-03-05 13:39:53

标签: php mysqli

每当我在服务器上运行它时,它都会返回以下错误:

  

您的SQL语法有错误;查看与您的MariaDB服务器版本对应的手册,以便在'表单(姓名,电子邮件,电话,主题,评论)附近使用正确的语法('james Key','datu @ yahoo。'在第1行

<html lang="en">
  <head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

    <!-- Bootstrap CSS -->

    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">

    <title>Contact Form</title>

      <style>
      .selector-for-some-widget {
  box-sizing: content-box;
}
      </style>

  </head>

  <body class="container">

      <div class="container">

    <h1>Contact Form</h1>

          <div id="error"> 
              <?php 
              echo $error; 
                  ?>
          </div>

  <form method= "post">

       <div class="form-group">

        <label for="exampleFormControlSelect1">Title</label>
        <select class="form-control" id="exampleFormControlSelect1">
          <option>Mr</option>
          <option>Mrs</option>
          <option>Prof</option>
          <option>Sir</option>
          <option>Miss</option>
        </select>

  </div>

        <div class="form-group">
        <label for="name">Name</label>
        <input type="text" name="name" class="form-control" id="name" placeholder="Oladele James">
  </div>

  <div class="form-group">
        <label for="exampleFormControlInput1">Email address</label>
        <input type="email" class="form-control" name="email" id="email" placeholder="name@example.com">
  </div>


  <div class="form-group">
        <label for="Telephone">Telephone</label>
        <input type="number" class="form-control" id="telephone" name="telephone" placeholder="+44 -77456 - 12134">
  </div>

  <div class="form-group">
    <label for="exampleFormControlInput1">Subject</label>
        <input type="text" class="form-control" name="subject" id="subject" placeholder="Title of what you want to talk about">
  </div>
  <div class="form-group">
    <label for="Textarea">What will you like to ask us</label>
    <textarea class="form-control" id="comment" name="comment" rows="3"></textarea>
  </div>

<button type="submit" id="submit" name="submit"class="btn btn-primary">Submit</button>
</form>



    </div>


<?php


$connection = mysqli_connect ("testing.mysql", "testing_com", "notreal", "notreal"); // not real data



if($connection){

    echo "Hurray, there is a connection" ."<br>";
}


if(isset($_POST["submit"])){

    $name = $_POST["name"];
    $telephone = $_POST["telephone"];
    $subject = $_POST["subject"];
    $email = $_POST["email"];
    $comment =wordwrap( $_POST["comment"]);

    $email = filter_var($email, FILTER_SANITIZE_EMAIL);

$query = "INSERT INTO contact form(name, email, telephone, subject, comment) VALUES ('$name', '$email', '$telephone', '$subject', '$comment')";

    $result =mysqli_query($connection, $query);

    if ($result){

    echo '<div class="alert alert-success" role="alert">
  Your form has been successfully sent and someone in our team will be touch ASAP!
</div>';
    } 

    else {$error .='<div class="alert alert-danger" role="alert"><p><strong> Your form was not sent:</strong></p>'. '</div>' . mysqli_error($connection);

        }
}
?>

0 个答案:

没有答案