0

Good day to all! While Im tring to insert ', ), (, and other smybols, sql is not working. I cannot insert the sybols. I made my db utf8-general-ci but it does not help me. How can I fix it?

My Query is :

<?php
$con = mysqli_connect("localhost", "root", "", "db");
if(isset($_POST['submit'])){
    $name = $_FILES['file']['name'];
    $temp = $_FILES['file']['tmp_name'];
    $depart=$_POST['depart']; 
    $boshqarma=$_POST['boshqarma'];
    $mavzu=$_POST['mavzu'];
    $qisqacha=$_POST['qisqacha'];
    $hodim=$_POST['hodim'];
    $tel=$_POST['tel'];
    move_uploaded_file($temp, "upload/".$name);
    $sql = "INSERT INTO video (id, name, depart, boshqarma, mavzu, hodim, tel, qisqacha ) 
    VALUES
     ('', '$name','$depart', '$boshqarma', '$mavzu', '$hodim', '$tel', '$qisqacha')";
    if(mysqli_query($con,$sql)){    
    }       
}
?>

2 Answers2

0

[...] VALUES ('' [...]

Field id is often a primary key so '' would not fit with the column description (usually non-negative integer).

By the way you should be using PDO and prepared statements for a safer use of your database. Good luck!

Chocorean
  • 807
  • 1
  • 8
  • 25
0

Try like this

<?php
$con = mysqli_connect("localhost", "root", "", "db");
if(isset($_POST['submit'])){
    $name = $_FILES['file']['name'];
    $temp = $_FILES['file']['tmp_name'];
    $depart= mysqli_real_escape_string ($con,$_POST['depart']); 
    $boshqarma= mysqli_real_escape_string($con,$_POST['boshqarma']);
    $mavzu= mysqli_real_escape_string($con,$_POST['mavzu']);
    $qisqacha= mysqli_real_escape_string($con,$_POST['qisqacha']);
    $hodim= mysqli_real_escape_string($con,$_POST['hodim']);
    $tel= mysqli_real_escape_string($con,$_POST['tel']);
    move_uploaded_file($temp, "upload/".$name);
    $sql = "INSERT INTO video (id, name, depart, boshqarma, mavzu, hodim, tel, qisqacha ) 
    VALUES
     ('', '$name','$depart', '$boshqarma', '$mavzu', '$hodim', '$tel', '$qisqacha')";
    if(mysqli_query($con,$sql)){    
    }       
}
?>

One more thing you are inserting id hope you doing correctly in most of the cases, id is auto increment so we don't have to insert in query.

Nirav Bhoi
  • 559
  • 9
  • 17