PHP MySqli查询无法正常工作

时间:2015-09-11 03:23:08

标签: php mysql mysqli

我想将数据插入我的数据库,但查询无效。我在另一个页面中使用此代码,但它工作。对于这个页面,似乎没有用。

这是我的upload.php

<?php
include_once("connect.php");
//Fetching Values from URL
if (isset($_POST['submit'])) {
    $nama_program=$_POST['nama_program'];
    $deskripsi=$_POST['deskripsi'];
    $code=$_POST['link_youtube'];
    $link_youtube="<iframe width='420' height='315' src='https://www.youtube.com/embed/".$code."' frameborder='0' allowfullscreen></iframe>";
    $link_twitter=$_POST['link_twitter'];
    $rating=$_POST['rating'];
    $image=$_POST['uploafimage'];
    $target_dir = "images/";
    $target_file = $target_dir . basename($_FILES["uploadimage"]["name"]);

    $result=$mysqli->query("INSERT INTO program(nama, deskripsi, link_youtube, link_twitter, image, rating, slider, twtiter) VALUES('$nama_program','$deskripsi','$link_youtube','$link_twitter','$target_file','$rating', 0, 0)");
    if($result === TRUE){
        echo "Congrats Your data hase been saved";
        } else{
            echo"There is eror here".$result;
        }
} else{
    echo "Error";
    }
?>

这是我的表格

<form action="upload.php" method="post" enctype="multipart/form-data">
    <input type="text" class="form-control" id="nama_program" name="nama_program">
    <textarea class="form-control textarea" name="deskripsi" id="deskripsi"></textarea>
    <textarea class="form-control textarea" name="link_youtube" id="link_youtube"></textarea>
    <textarea class="form-control textarea" name="link_twitter" id="link_twitter"></textarea>
    <select name="rating" id="rating" class="form-control">
             <option>Rating</option>
             <option>1</option>
             <option>2</option>
             <option>3</option>
    <input type="file" name="uploadimage" id="uploadimage">
    <button type="submit" class="btn btn-info">
           submit
    </button>
</form>

mysqli出了什么问题?我使用此enctype="multipart/form-data"因为我想上传图片,但首先查询无效。

这是我的connect.php

 <?php
 $host = "localhost";
 $user = "*****";
 $pass = "****";
 $dbnm = "*******";
 $mysqli = new mysqli($host, $user, $pass, $dbnm);
 if($mysqli->connect_errno > 0){
    die('Unable to connect to database [' . $mysqli->connect_error . ']');
}
?>

1 个答案:

答案 0 :(得分:0)

mysqli_query($yourcon,"INSERT INTO program(nama, deskripsi, link_youtube, link_twitter, image, rating, slider, twtiter) VALUES ('$nama_program','$deskripsi','$link_youtube','$link_twitter','$target_file','$rating', 0, 0)");
  

提供有关击球手的问题和错误的更多说明   溶液