объект класса mysqli _connect не может быть преобразован в строку в строке 135 - PullRequest
0 голосов
/ 17 февраля 2019

, когда я запускаю код, он выдает ошибку объекта класса mysqli_connect, который не может быть преобразован в строку в строке 135. Пожалуйста, кто-нибудь предоставит мне решение этой проблемы.

Я попытался найти решение, но нетодин работал на меня.ниже приведен код, показывающий ошибку.

$ row = mysqli_connect ("$ con, $ insert_product");

принят для запуска, но показывает ошибку в строке 135. какую ошибку я допустил.полный код здесь

<?php require_once ("includes/db.php"); 
    ?>
    <!DOCTYPE html>
    <html>
    <head>
        <title> product</title>
    </head>
    <body>
    <form method="post" action="insert_product.php" enctype="multipart/form-data">
    <table width="700" align="center">
        <tr>
            <td><h2>insert new product</h2></td>
        </tr>
        <tr>
            <td>Product title</td>
            <td><input type="text" name="product_title"></td>
        </tr>
        <tr>
            <td>Product category</td>
            <td><select name="product_cat">
               <option>Select a category</option>
               <?php 
                  $get_cats = "select * from category";
                $run_cats= mysqli_query($con,$get_cats);
                while ($row_cats=mysqli_fetch_array($run_cats))
                {
                  $cat_id = $row_cats['cat_id'];
                    $cat_title=$row_cats['cat_title'];




                 echo "<option value='$cat_id'>$cat_title</option>";
                  }

                ?>
               </select>
            </td>
        </tr>
        <tr>
          <td>Product brand</td>
            <td><select name="product_brand">
               <option>Select brand</option>
               <?php 
                  $get_brand = "select * from brand";
                $run_brand= mysqli_query($con,$get_cats);
                while ($row_brand=mysqli_fetch_array($run_brand))
                {
                    $brand_id = $row_brand['brand_id'];
                    $brand_title=$row_brand['brand_title'];
                    echo "<option value='$cat_id'>$cat_title</option>";
                 }

                ?>
               </select>
            </td>
        </tr>
        <tr>
           <td>product image1</td>
            <td><input type="file" name="product_img1"></td>
        </tr>
        <tr>
           <td>Product image2</td>
            <td><input type="file" name="product_img2"></td>
        </tr>
        <tr>
            <td>Product image3</td>
            <td><input type="file" name="product_img3"></td>
        </tr>
        <
        <tr>
            <td>Product price</td>
            <td><input type="number" name="product_price"></td>
        </tr>
        <tr>
            <td>Product desceptration</td>
            <td><input type="text" name="product_desc"></td>
        </tr>

        <tr>
            <td>Product keyword</td>
            <td><input type="number" name="product_keyword"></td>
        </tr>
        <tr>
            <td><input type="submit" value="submit" name="submit"></td>
        </tr>

    </table>

    </form>
    </body>
    </html>


    <?php 

      if(isset($_POST['submit']))
      {
        $product_title=$_POST['product_title'];
        $product_cat=$_POST['product_cat'];
        $product_brand=$_POST['product_brand'];
        $product_price=$_POST['product_price'];
        $product_desc=$_POST['product_desc'];
        $status='on';
        $product_keyword=$_POST['product_keyword'];

        //image name

        $product_img1 = $_FILES['product_img1']['name'];
        $product_img2 = $_FILES['product_img2']['name'];
        $product_img3 = $_FILES['product_img3']['name'];

         //image temp names

        $temp_name1 = $_FILES['product_img1']['tmp_name'];
        $temp_name2 = $_FILES['product_img2']['tmp_name'];
        $temp_name3 = $_FILES['product_img3']['tmp_name'];


        if($product_title=='' OR  $product_cat=='' OR $product_brand=='' OR $product_price=='' OR $product_desc=='' OR $product_keyword=='' OR $product_img1=='' OR $product_img2=='' OR $product_img3=='')
          {
            echo "<script> alert ('please insert the data in the form')</script>";
            exit();
          }

        else{
            //uploadinimage to the folder
            move_uploaded_file($temp_name1,"product_images/$product_img1");
            move_uploaded_file($temp_name2, "product_images/$product_img2");
            move_uploaded_file($temp_name3,"product_images/$product_img3");

        }

        $insert_product = "insert into products (cat_id,brand_id,date,product_title,product_img1,product_img2,product_img3,product_brand,product_price,product_desc,status) values ('$product_cat','$product_brand',NOW(),'$product_title','$product_img1','$product_img2',$product_img3,'product_brand','product_price','product_desc','product_keyword')";
      $row = mysqli_connect("$con,$insert_product");
        if($row)

        {
            echo "<script> alert('insert sucessfully')</script>";
        }
        else
        {
            echo "<script> alert(' unsucessfull to insert')</script>";
        }
    }
        ?>

1 Ответ

0 голосов
/ 17 февраля 2019

Не думаю, что вы собираетесь снова подключиться.Скорее всего, вы пытаетесь выполнить запрос?

Ваш код:

$insert_product = "insert into products (cat_id,brand_id,date,product_title,product_img1,product_img2,product_img3,product_brand,product_price,product_desc,status) values ('$product_cat','$product_brand',NOW(),'$product_title','$product_img1','$product_img2',$product_img3,'product_brand','product_price','product_desc','product_keyword')";
$row = mysqli_connect("$con,$insert_product");

Вы не только ссылаетесь на переменную, никогда не определенную в сценарии (хотя она, вероятно, находится втребуемый файл вверху), но вы передаете запрос прямо к mysqli_connect () .Я представляю, что вы на самом деле хотели сделать:

$insert_product = "insert into products (cat_id,brand_id,date,product_title,product_img1,product_img2,product_img3,product_brand,product_price,product_desc,status) values ('$product_cat','$product_brand',NOW(),'$product_title','$product_img1','$product_img2',$product_img3,'product_brand','product_price','product_desc','product_keyword')";
$row = mysqli_query($con, $insert_product);
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...