Error Insert mysqli

Asked

Viewed 48 times

-1

How to do INSERT correctly? Not inserting !

 $id =  $_GET['id'];
 $queryrun=mysqli_query($conn,"SELECT image_path FROM tbl_image WHERE 
 id='$id' ");
 $row=mysqli_fetch_object($queryrun);
if($row->image_path!== $document)
 {
 unlink("upload/".$row->image_path);
 }
 $query = " UPDATE tbl_image SET image_album,image_text = 
'$img_album','$img_text',image_path = '$document' where id = '$id' ";
 $queryrun = mysqli_query($conn,$query);
 $_SESSION['msg'] = "Your Data Updated Successfully";   
}

Doubt if the Internet is correct !

$query = " UPDATE tbl_image SET image_album,image_text = 
'$img_album','$img_text',image_path = '$document' where id = '$id' ";

Attempt to specify for each value ? same error

$query = "INSERT INTO tbl_image SET image_album,SET image_text = 
'$img_album','$img_text',image_path = '$document'  ";

Solved in this way

 $query = "INSERT INTO tbl_image SET image_album = '$img_album', image_text = '$img_text', image_path = '$document'  ";
  • Any error message appears? see if it shows any: $queryrun = mysqli_query($conn,$query) or die(mysqli_error($conn);

  • no error message and does not insert !

  • 1

    There is an update there and no Insert ;)

  • P each column vc must specify a value, which it does not have at all in its update.

  • and how it would be to specify for each value ?

  • Thus $query = "UPDATE tbl_image SET 
 image_album = 'valor',
 image_text = '$img_album',
 '$img_text',image_path = '$document'
 where id = '$id' "; tested the code of the first comment, returned no error?

  • tested yes! works like $query = " UPDATE tbl_image SET image_album = '$img_album',image_path = '$Document' Where id = '$id' "; Dae It inserts but I wanted to add one more table

Show 2 more comments

2 answers

2

If you want to include a new record with alternative syntax Mysql should specify the column and its value, according to the code below.

$query = "INSERT INTO tbl_image SET 
                      image_album = '$img_album' ,
                      image_text = '$img_text',
                      image_path = '$document'";

Or in classical syntax:

$query = "INSERT INTO tbl_image (image_album, image_text, image_path) 
          VALUES ('$img_album', '$img_text', '$document')";

1

Try it this way:

$query = " UPDATE tbl_image SET image_album='$img_album',image_text = 
'$img_text',image_path = '$document' where id = '$id' ";

Correct syntax:

UPDATE tablename SET column1 = value1, column2 = value2, ... WHERE condition;

Browser other questions tagged

You are not signed in. Login or sign up in order to post.