mysqli_real_escape_string()期望参数2是字符串吗?

时间:2019-07-02 11:53:38

标签: php

问题出在哪里?有人可以告诉我我在哪里错吗?

  

mysqli_real_escape_string()期望参数2为字符串,数组   在

中给出
//submit
    if ($_POST['submit']) {
    $user=mysqli_real_escape_string($con,$_POST['user']);
    $email=mysqli_real_escape_string($con,$_POST['email']);
    $link=mysqli_real_escape_string($con,$_POST['link']);
    $subject=mysqli_real_escape_string($con,$_POST['subject']);
        // required
    if(!empty($_POST['user']) && !empty($_POST['email']) && !empty($_POST['link']) && !empty($_POST['subject'])){
        // captcha
    if (!empty($_POST["captcha"])&&$_POST["captcha"]!="" && $_SESSION["code"]==$_POST["captcha"]) {
        //inserting
    $sql = "INSERT INTO contact (`user`,`email`,`link`,`subject`)VALUES('$user','$email','$link','$subject')";

完整代码

 <?php
echo '
<main><section><form method="POST" class="contact-form">
  <span><i class="fas fa-info-circle"></i>contact</span>
  <ul>
    <li>
      <i class="fa fa-user form-icon"></i>
      <input type="text" placeholder="name" required name="user" />
    </li>
    <li>
      <i class="fa fa-at form-icon"></i>
      <input type="text" placeholder="email" required  name="email"/>
    </li>
    <li>
      <i class="fa fa-link form-icon"></i>
      <input type="text" placeholder="link" required name="link"/>
    </li>
    <li>
      <img class="img-capatcha" src="captcha.php">
    </li>
    <li>
      <i class="fa fa-paper-plane form-icon"></i>
      <input type="text" placeholder="captcha" required name="captcha" />
    </li>
    <li>
      <i class="fa fa-envelope form-icon"></i>
      <textarea placeholder="subject" rows="2" required name="subject"></textarea>
    </li>
    <li>
      <input type="submit" placeholder="Submit" value="ارسال" required name="submit"/>
    </li>
  </ul></form>
  ';
//submit
    if ($_POST['submit']) {
    $user=mysqli_real_escape_string($con,$_POST['user']);
    $email=mysqli_real_escape_string($con,$_POST['email']);
    $link=mysqli_real_escape_string($con,$_POST['link']);
    $subject=mysqli_real_escape_string($con,$_POST['subject']);
        // required
    if(!empty($_POST['user']) && !empty($_POST['email']) && !empty($_POST['link']) && !empty($_POST['subject'])){
        // captcha
    if (!empty($_POST["captcha"])&&$_POST["captcha"]!="" && $_SESSION["code"]==$_POST["captcha"]) {
        //inserting
    $sql = "INSERT INTO contact (`user`,`email`,`link`,`subject`)VALUES('$user','$email','$link','$subject')";
    $result = mysqli_query($con, $sql);
    if ($result) {
    echo "
    <div id='oops'>
      <div id='succ'>
        <p><i class='fas fa-check'></i>succ</p>
      </div>
    </div>";
    }
    else{
    echo "
    <div id='oops'>
      <div id='alert'>
        <p><i class='fas fa-times'></i>error in inserting</p>
      </div>
    </div>
    ";
    }
    }
    else{
    echo
    "<div id='oopss'>
      <div id='warning'>
        <p><i class='fas fa-exclamation-circle'></i>error in captcha</p>
      </div>
    </div>
    ";
    }
    }
    else{
    echo
    "<div id='oopss'>
      <div id='warning'>
        <p><i class='fas fa-exclamation-circle'></i>all input required  </p>
      </div>
    </div>
    ";
    }
    }
    ?>

连接代码

$host = "localhost"; 
$user = "root"; 
$password = "123456789"; 
$dbname = "test";
$con = mysqli_connect($host, $user, $password,$dbname);

0 个答案:

没有答案